You are here: Re: Combining 2 preg matches. « PHP Programming Language « IT news, forums, messages
Re: Combining 2 preg matches.

Posted by frizzle on 07/16/06 13:55

Chung Leong wrote:
> frizzle wrote:
> > Hi group,
> >
> > I have a function which validates a string using preg match.
> > A part looks like
> >
> > if( !preg_match( '/^([a-z0-9]+(([a-z0-9_-]*)?[a-z0-9])?)$/', $string )
> > ||
> > preg_match( '/(--|__)+/' ,$string) ) {
> >
> > i wonder how i could combine those two into one ...
> > I tried a few different options of putting the second match into the
> > first one,
> > using things like [^__]+ etc, but nothing worked for me.
> > it should prevent double (or more) dashes or underscores behind each
> > other.
> > hello-there = ok
> > hello--there != ok
> >
> > Any help would be great.
> >
> > Frizzle.
>
> What you need is a lookahead and lookbehind assertion on the dash and
> underscore, stating that they're acceptable only if there're letters in
> front and behind them:
>
> /^(?:[a-z]|(?<=[a-z])[-_](?=[a-z]))+$/

/^(?:[a-z]|(?<=[a-z])[-_](?=[a-z]))+$/

wowowow, could you explain a little on this ?
like the : and ?<= parts

(i assume 0-9 should still be included??)

Frizzle.

 

Navigation:

[Reply to this 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

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