You are here: Re: preg_match question « PHP Programming Language « IT news, forums, messages
Re: preg_match question

Posted by malatestapunk on 12/16/97 11:58

Jørn Dahl-Stamnes wrote:
> I try to use preg_match to find out if a string begins with either "http",
> "/somethime" or "../something". In my php script I have the following line:
>
> if (0 == preg_match("/^(http.+)|(\/[a-z].+/)|(\.\.[a-z]+)/i",$string)
>
> But I get a:
>
> Warning: Unknown modifier ')' in myscript.php at line nn
>
> What's wrong with the pattern?
>
> --
> Jørn Dahl-Stamnes
> http://www.dahl-stamnes.net/dahls/

If that is your exact line of code, then you missed escaping a slash
(trailing slash in second matching group, after the plus sign):

.... |(\/[a-z].+/)| ...

So, when parser reaches that slash, it believes the regex itself is now
complete and tries to interpret everything after it as modifiers. Since
you have closed brace after the unescaped slash, and it is not a valid
regex modifier, it gives you the "unknown modifier" error.

If you find yourself working with regular expressions a lot, or if you
find them hard to understand or to work with, you may want to try
something like Regex Coach (http://weitz.de/regex-coach/), or a similar
tool. It helps me a lot, especially when things get complicated.

 

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

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