[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
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: pharo-project-bounces@lists.gforge.inria.fr [pharo-project-bounces@lists.gforge.inria.fr] on behalf of recursive68@gmail.com [recursive68@gmail.com] Sent: Saturday, February 11, 2012 5:27 PM To: pharo-project@lists.gforge.inria.fr 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
http://rmod.lille.inria.fr/pbe2/ https://gforge.inria.fr/scm/viewvc.php/*checkout*/PharoByExampleTwo-Eng/Rege... I would be surprised that we call a regexp package something that cannot handle Stef On Feb 11, 2012, at 11:27 PM, recursive68@gmail.com 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
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, <recursive68@gmail.com> 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
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, <recursive68@gmail.com> 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
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 <stephane.ducasse@inria.fr> 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, Â <recursive68@gmail.com> 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
'a1b' matchesRegex: '[[:alnum:]]*((\d+[[:alnum:]]*[[:alpha:]]+)|([[:alpha:]]+[[:alnum:]]*\d+))[[:alnum:]]*'. perhaps? Regards, Gary ----- Original Message ----- From: "Stéphane Ducasse" <stephane.ducasse@inria.fr> To: <Pharo-project@lists.gforge.inria.fr> 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, <recursive68@gmail.com> 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
participants (5)
-
Gary Chambers -
Lukas Renggli -
recursive68@gmail.com -
Schwab,Wilhelm K -
Stéphane Ducasse