|
Posted by Rik on 07/16/06 14:46
Rik wrote:
> $regex ='/ #opening delimiter
> ^ #start of string
> (?: #start of non-capturing group
> [a-z] #any character between a and z
> | #OR
> (?<= #start of positive lookbehind (is preceeded
> by..) [a-z] #any character between a and z
> ) #end of positive lookbehind
> [-_] #character - or _ (not incorrect, but probably
> better to [_\-],[_-] or [\-_]
> (?= #start of positive lookahead
> [a-z] #any character between a and z
> ) #end of positive lookahead
> ) #end of non-capturing group
> + #1 or more times, greedy
> $ #end of string
> /x';
>
It just occured to me that, allthough a wonderfull example:
$regex ='/^(?:[a-z]|[a-z][_\-][a-z])+$/';
....will do just fine.
equally so:
$regex ='/^(?:[a-z]+(?:[_\-][a-z]+))+$/';
Lookahead & -behind are unneccessary in this case, and this keep it simple.
Grtz,
--
Rik Wasmus
Navigation:
[Reply to this message]
|