Regular expression

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Regular expression

recursive
Hi,

Is it possible to use the VB-Regexp package to construct a single regular expression that ensures a string is alphanumeric and contains both at least one number and alphabetic character. 

Looking at the regexp package and documentation it doesn't appear so. In javascript or perl you use something like this with lookahead assertions:

^(?=.*[a-zA-Z])(?=.*[0-9]).*$

I have something working using multiple regexp's but wondered if a more typical regexp was possible using the package ?

Thanks


Reply | Threaded
Open this post in threaded view
|

Re: Regular expression

Schwab,Wilhelm K
I've used the package to good effect, but you are beyond me - hopefully someone else can offer some real help.  You might something in the Reg ex chapter on

  http://pharobyexample.org/

Look under "Pharo by Example 2" on the right side of the page.

HTH (some).

Bill




From: [hidden email] [[hidden email]] on behalf of [hidden email] [[hidden email]]
Sent: Saturday, February 11, 2012 5:27 PM
To: [hidden email]
Subject: [Pharo-project] Regular expression

Hi,

Is it possible to use the VB-Regexp package to construct a single regular expression that ensures a string is alphanumeric and contains both at least one number and alphabetic character. 

Looking at the regexp package and documentation it doesn't appear so. In javascript or perl you use something like this with lookahead assertions:

^(?=.*[a-zA-Z])(?=.*[0-9]).*$

I have something working using multiple regexp's but wondered if a more typical regexp was possible using the package ?

Thanks


Reply | Threaded
Open this post in threaded view
|

Re: Regular expression

Stéphane Ducasse
In reply to this post by recursive
http://rmod.lille.inria.fr/pbe2/
https://gforge.inria.fr/scm/viewvc.php/*checkout*/PharoByExampleTwo-Eng/Regex/Regex.pdf?root=pharobooks

I would be surprised that we call a regexp package something that cannot handle
Stef

On Feb 11, 2012, at 11:27 PM, [hidden email] wrote:

> Hi,
>
> Is it possible to use the VB-Regexp package to construct a single regular expression that ensures a string is alphanumeric and contains both at least one number and alphabetic character.
>
> Looking at the regexp package and documentation it doesn't appear so. In javascript or perl you use something like this with lookahead assertions:
>
> ^(?=.*[a-zA-Z])(?=.*[0-9]).*$
>
> I have something working using multiple regexp's but wondered if a more typical regexp was possible using the package ?
>
> Thanks
>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Regular expression

Lukas Renggli
In reply to this post by recursive
VB-Regexp does not support any of the following common regular
expression features: lookahead, lookbehind, recursion, multiplicity
ranges, non-greedy quantifier, shy groups, directives, conditionals,
named captures, back references, and comments.

You can (conceptually) do all this with PetitParser, but then you are
not writing a regular expression anymore but a (PEG) parser.

There was once a plugin that called an external regular expression
library (I think it used the library Perl is using) that supported the
features you are looking for.

Lukas

On 11 February 2012 23:27,  <[hidden email]> wrote:

> Hi,
>
> Is it possible to use the VB-Regexp package to construct a single regular
> expression that ensures a string is alphanumeric and contains both at least
> one number and alphabetic character.
>
> Looking at the regexp package and documentation it doesn't appear so. In
> javascript or perl you use something like this with lookahead assertions:
>
> ^(?=.*[a-zA-Z])(?=.*[0-9]).*$
>
> I have something working using multiple regexp's but wondered if a more
> typical regexp was possible using the package ?
>
> Thanks
>
>



--
Lukas Renggli
www.lukas-renggli.ch

Reply | Threaded
Open this post in threaded view
|

Re: Regular expression

Stéphane Ducasse
thanks for the update.
Now may be the problem can be still express with regex.

Stef

On Feb 12, 2012, at 10:49 AM, Lukas Renggli wrote:

> VB-Regexp does not support any of the following common regular
> expression features: lookahead, lookbehind, recursion, multiplicity
> ranges, non-greedy quantifier, shy groups, directives, conditionals,
> named captures, back references, and comments.
>
> You can (conceptually) do all this with PetitParser, but then you are
> not writing a regular expression anymore but a (PEG) parser.
>
> There was once a plugin that called an external regular expression
> library (I think it used the library Perl is using) that supported the
> features you are looking for.
>
> Lukas
>
> On 11 February 2012 23:27,  <[hidden email]> wrote:
>> Hi,
>>
>> Is it possible to use the VB-Regexp package to construct a single regular
>> expression that ensures a string is alphanumeric and contains both at least
>> one number and alphabetic character.
>>
>> Looking at the regexp package and documentation it doesn't appear so. In
>> javascript or perl you use something like this with lookahead assertions:
>>
>> ^(?=.*[a-zA-Z])(?=.*[0-9]).*$
>>
>> I have something working using multiple regexp's but wondered if a more
>> typical regexp was possible using the package ?
>>
>> Thanks
>>
>>
>
>
>
> --
> Lukas Renggli
> www.lukas-renggli.ch
>


Reply | Threaded
Open this post in threaded view
|

Re: Regular expression

Lukas Renggli
Yes, in this particular example one can rewrite the expression as

    ^.*(([a-zA-Z].*[0-9])|([0-9].*[a-zA-Z])).*$

and it (probably) does the same.

However, this cannot be done in a general case, because lookahead are
not part of the (currently) recognizable types of languages with
VB-Regexp. It shouldn't be too difficult to add positive and negative
lookahead to VB-Regexp (this is essentially like #and and #not in
PetitParser), but getting the semantics exactly right is more tricky.

Lukas

On 12 February 2012 15:40, Stéphane Ducasse <[hidden email]> wrote:

> thanks for the update.
> Now may be the problem can be still express with regex.
>
> Stef
>
> On Feb 12, 2012, at 10:49 AM, Lukas Renggli wrote:
>
>> VB-Regexp does not support any of the following common regular
>> expression features: lookahead, lookbehind, recursion, multiplicity
>> ranges, non-greedy quantifier, shy groups, directives, conditionals,
>> named captures, back references, and comments.
>>
>> You can (conceptually) do all this with PetitParser, but then you are
>> not writing a regular expression anymore but a (PEG) parser.
>>
>> There was once a plugin that called an external regular expression
>> library (I think it used the library Perl is using) that supported the
>> features you are looking for.
>>
>> Lukas
>>
>> On 11 February 2012 23:27,  <[hidden email]> wrote:
>>> Hi,
>>>
>>> Is it possible to use the VB-Regexp package to construct a single regular
>>> expression that ensures a string is alphanumeric and contains both at least
>>> one number and alphabetic character.
>>>
>>> Looking at the regexp package and documentation it doesn't appear so. In
>>> javascript or perl you use something like this with lookahead assertions:
>>>
>>> ^(?=.*[a-zA-Z])(?=.*[0-9]).*$
>>>
>>> I have something working using multiple regexp's but wondered if a more
>>> typical regexp was possible using the package ?
>>>
>>> Thanks
>>>
>>>
>>
>>
>>
>> --
>> Lukas Renggli
>> www.lukas-renggli.ch
>>
>
>



--
Lukas Renggli
www.lukas-renggli.ch

Reply | Threaded
Open this post in threaded view
|

Re: Regular expression

Gary Chambers-4
In reply to this post by Stéphane Ducasse
'a1b' matchesRegex:
'[[:alnum:]]*((\d+[[:alnum:]]*[[:alpha:]]+)|([[:alpha:]]+[[:alnum:]]*\d+))[[:alnum:]]*'.

perhaps?

Regards, Gary

----- Original Message -----
From: "Stéphane Ducasse" <[hidden email]>
To: <[hidden email]>
Sent: Sunday, February 12, 2012 2:40 PM
Subject: Re: [Pharo-project] Regular expression


thanks for the update.
Now may be the problem can be still express with regex.

Stef

On Feb 12, 2012, at 10:49 AM, Lukas Renggli wrote:

> VB-Regexp does not support any of the following common regular
> expression features: lookahead, lookbehind, recursion, multiplicity
> ranges, non-greedy quantifier, shy groups, directives, conditionals,
> named captures, back references, and comments.
>
> You can (conceptually) do all this with PetitParser, but then you are
> not writing a regular expression anymore but a (PEG) parser.
>
> There was once a plugin that called an external regular expression
> library (I think it used the library Perl is using) that supported the
> features you are looking for.
>
> Lukas
>
> On 11 February 2012 23:27,  <[hidden email]> wrote:
>> Hi,
>>
>> Is it possible to use the VB-Regexp package to construct a single regular
>> expression that ensures a string is alphanumeric and contains both at
>> least
>> one number and alphabetic character.
>>
>> Looking at the regexp package and documentation it doesn't appear so. In
>> javascript or perl you use something like this with lookahead assertions:
>>
>> ^(?=.*[a-zA-Z])(?=.*[0-9]).*$
>>
>> I have something working using multiple regexp's but wondered if a more
>> typical regexp was possible using the package ?
>>
>> Thanks
>>
>>
>
>
>
> --
> Lukas Renggli
> www.lukas-renggli.ch
>