preg_match(); - Unknown modifier '+' [duplicate] preg_match(); - Unknown modifier '+' [duplicate] php php

preg_match(); - Unknown modifier '+' [duplicate]


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().


Try this code:

preg_match('/[a-zA-Z]+<\/a>.$/', $lastgame, $match);print_r($match);

Using / as a delimiter means you also need to escape it here, like so: <\/a>.

UPDATE

preg_match('/<a.*<a.*>(.*)</', $lastgame, $match);echo'['.$match[1].']';

Might not be the best way...


This happened to me because I put a variable in the regex and sometimes its string value included a slash. Solution: preg_quote.