Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Regular expression help
- Jon Combe
September 24, 2009, 12:52 pm
rate this thread
I realise this is not the ideal group, because there doesn't seem to
be a regular expressions group but since most Perl developers use
regular expressions I'm hoping someone will know! I use regular
expressions a lot but I have come accross a request that has me
stumped. The following needs to be done in a single regular
Validate length to a minimum and maximum number of characters
Must contain at least one vowel
Must not contain any numbers
Must contain no more than 2 adjacent repeated characters (so aa is OK,
but aaa is not)
I can write a single regular expression to do 2 of those but I cannot
come up with a single regular expression to do all 4. Is it actually
possible? I realise it could easily be done with several expressions
and an "and" statement (and probably faster too), but this needs to be
plugged in to an application that accepts only a single regular
Re: Regular expression help
You can do it with a lot of look-ahead assertions:
(?= .* [aeiouy] ) # At least one vowel
(?! .* [0-9] ) # Does not contain number
(?! .* (\w) ) # no more than 2 adjacent repeated characters
. # Between 5 and 8 chars
But the variant of regular expressions your application is using must
have both positive and negative lookaheads for this to work.
- » FAQ 5.34 How do I close a file descriptor by number?
- — Next thread in » PERL Discussions
- » How to check if a module is installed in Strawberry?
- — Previous thread in » PERL Discussions