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
How to Disable Redirection After Login_Check in Symfony 2
How to Know If MySQLnd Is the Active Driver
Calculating Distance Between Zip Codes in PHP
How to Fix Memory Getting Exhausted with PHPexcel
Pdo + MySQL and Broken Utf-8 Encoding
How to Get Wkhtmltopdf to Execute via PHP
How to Prevent the Cron Job Execution, If It Is Already Running
Which Mime Type Should I Use for Mp3
Rounding to Nearest Fraction (Half, Quarter, etc.)
How to Loop Through a MySQL Query via Pdo in PHP
What Is the Max Key Size for an Array in PHP
PHP Simplexml Check If a Child Exists
PHP 7.4 Deprecated Get_Magic_Quotes_Gpc Function Alternative
Jquery - Uncaught Typeerror: Cannot Use 'In' Operator to Search for '324' In