|
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]
|