Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP RegExpr error Unkown modifier '('

Tags:

regex

php

I have this regular expression:

([http://some.url.com/index.php?showtopic=\"]*)([0-9]+(?:\.[0-9]*)?)

its for extracting links to topics from forum

Now when i use it in my script

$url = "([http://some.url.com/index.php?showtopic=\"]*)([0-9]+(?:\.[0-9]*)?)";

preg_match_all spits: "Unknown modifier '('"

This is also the call to preg_match

preg_match_all($url, $str, $matches,PREG_OFFSET_CAPTURE,3);

Can anyone help me with this obviously stupid problem

like image 557
Anonymous Avatar asked Dec 12 '25 07:12

Anonymous


1 Answers

You need to wrap your regular expression in delimiters. Any character that isn't a special PCRE metacharacter will do, so I'll use #:

$url = "#([http://some.url.com/index.php?showtopic=\"]*)([0-9]+(?:\.[0-9]*)?)#";

You can learn more about delimiters in the PHP manual section for PCRE delimiters.

like image 197
BoltClock Avatar answered Dec 15 '25 12:12

BoltClock