Warning: Preg_Match() [Function.Preg-Match]: Unknown Modifier '/'

Warning: preg_match() [function.preg-match]: Unknown modifier '/'

preg_match('~"http://(.*)"~iU', $code, $matches);

Your issue was you need delimiters (I chose ~) to use with the pattern. See the preg_match() man page for more information.

When does preg_match(): Unknown modifier error occur?

If the first name or last name contains a /, your regex will look something like:

/john/doe$/

To preg_match, this looks like the regex is /john/, with the trailing doe$/ being the modifiers. Those are of course invalid modifiers. You need to escape the regex delimiters (/) inside the regex itself using preg_quote.

preg_match error Unknown modifier '('

Escape / in the regular expression.

"/^([1-9]|0[1-9]|[1,2][0-9]|3[0,1])\/([1-9]|1[0,1,2])\/\d{4} ([0-1][0-9]|[2][0-3])(:([0-5][0-9])){1,2}(:([0-5][0-9])){1,2}$/"
# ^ ^

Otherwise, / is recognised as end of the regular expression.

Or use different delimiters:

"#^([1-9]|0[1-9]|[1,2][0-9]|3[0,1])/([1-9]|1[0,1,2])/\d{4} ([0-1][0-9]|[2][0-3])(:([0-5][0-9])){1,2}(:([0-5][0-9])){1,2}$#"

preg_match(); - Unknown modifier '+'

You need to use delimiters with regexes in PHP. You can use the often used /, but PHP lets you use any matching characters, so @ and # are popular.

Further Reading.

If you are interpolating variables inside your regex, be sure to pass the delimiter you chose as the second argument to preg_quote().

PHP - preg_match and Unknown modifier error

The problem is the delimiter / because you use it in your regexp again.

You have to escape it \/ or use another delimiter like @:

if (preg_match("@([0-9]{2})[-/.]([0-9]{2})[-/.]([0-9]{4})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})@", $dateToTest, $tab) == false)

See the example #3 in the Docu. There is also a manual about delimiters.

Warning: preg_match() [function.preg-match]: Unknown modifier

Use preg_quote to quote regular expression characters.

Like this:

preg_quote($theKeyword, '/');

Where '/' is the delimiter in your regular expression.

Unknown modifier in preg_match() statement

Escape all the / or use another regex delimiter, i.e. ~ or #

if (preg_match("#$urlRegex#", $entry)) {

moreover, your regex could be shortened:

$urlRegex = "(https?|ftp)://([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&;%$-]+)*@)*((?:(25[0-5]|2[0-4]\d|[01]\d{2}|[1-9]\d|[1-9])\.){3}(25[0-5]|2[0-4]\d|[01]\d{2}|[1-9]\d|[1-9]|0)|localhost|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:\d+)*(($|[a-zA-Z0-9.,?'+\\&;%\$#=~_-]+))*";


Related Topics



Leave a reply



Submit