I need to build PHP regex patterns delimited by ASCII control characters, as suggested in PHP Regex delimiter, in order to match texts containing /
, ~
and "
.
The strange fact is, in order to manage double quotes I usually wrap my pattern in single quotes (e.g.
preg_match('x02^/some~"string"/x02u', '/some~"string"/')
); but this throws a “Warning: preg_match(): Delimiter must not be alphanumeric, backslash, or NUL in ***”.
However, if I wrap my pattern in double quotes and (obviously) escape the inner double quotes (e.g.
preg_match("x02^/some~"string"/x02u", '/some~"string"/')
), the pattern works as expected.
Could anyone explain me what’s happening? Thanks in advance!
muggy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1