Reply to RE: [PHP] Regex help

Your name:

Reply:


Posted by Michael Sims on 01/29/05 21:13

Bret Hughes wrote:
> On Sat, 2005-01-29 at 08:58, Michael Sims wrote:
>> kjohnson@zootweb.com 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}$/

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация