0

Currently using the following string as my pattern. (Warning: preg_match(): Unknown modifier '0')

$between = preg_match("(.*)".$check."(.*)", _allbetween($coords1, $coords2));

What am I doing wrong?

Have never used regular expressions in php before, please excuse this probably extremely simple question.

2 Answers2

2

You must add delimiters to your pattern and use preg_quote if $check contains a literal string:

preg_match("/(.*)".preg_quote($check)."(.*)/", _allbetween($coords1, $coords2));

Note that preg_match returns 1 or 0 (true or false), not the match result (see the php manual)

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
1

A regular expression in PHP must be enclosed by a pair of characters, that do not occur in the regexp itself (and if, they mus be escaped using a backslash).

Which character you use is defined through the first char – a ( in your case. But a bracket already has a special meaning in regexp.

You should enclose your regexp by the most common delimiter / (a slash), as in:

$between = preg_match( sprintf( '/(.*)%s(.*)/', preg_quote( $check ) ), _allbetween($coords1, $coords2));
feeela
  • 29,399
  • 7
  • 59
  • 71