I have this code :
$string1 = \"My name is \'Kate\' and im fine\";
$pattern = \"My name is \'(.*)\' and im fine\";
preg_match($pattern , $string1, $matches
You must specify a delimiter for your expression. A delimiter is a special character used at the start and end of your expression to denote which part is the expression. This allows you to use modifiers and the interpreter to know which is an expression and which are modifiers. As the error message states, the delimiter cannot be a backslash because the backslash is the escape character.
$pattern = "/My name is '(.*)' and im fine/";
and below the same example but with the i
modifier to match without being case sensitive.
$pattern = "/My name is '(.*)' and im fine/i";
As you can see, the i
is outside of the slashes and therefore is interpreted as a modifier.
Also bear in mind that if you use a forward slash character (/) as a delimiter you must then escape further uses of / in the regular expression, if present.