RE: Regex help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bret Hughes wrote:
> On Sat, 2005-01-29 at 08:58, Michael Sims wrote:
>> kjohnson@xxxxxxxxxxx wrote:
>>> I need a validation regex that will "pass" a string. The string can
>>> be no longer than some maximum length, and it can contain any
>>> characters except two consecutive ampersands (&) anywhere in the
>>> string.
>>>
>>> I'm stumped - ideas?
>>
>> Yup, use this perl regex:
>>
>> /^(?:(&)(?!&)|[^&]){1,5}$/
>
> Great explanation.  Thanks from one who has not had an exam for over
> ten years.

Thanks...I actually just realized that the parentheses around the first
ampersand are unnecessary (that was a leftover from a previous attempt), so
this is simpler and will work just as well:

/^(?:&(?!&)|[^&]){1,5}$/

Or if you don't care about capturing portions of the match and then throwing
them away:

/^(&(?!&)|[^&]){1,5}$/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux