Bret Hughes wrote:
> On Sat, 2005-01-29 at 08:58, Michael Sims wrote:
>> [EMAIL PROTECTED] 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

Reply via email to