I am generating regex automatically to validate URLs. To avoid clashes I am simply escaping regular text with \Q
and \E
. Unfortunately I discovered that this syntax does not work as it should in PHP:
reg_match('/\Qfoo/bar\E/', 'foo/bar')
PHP Warning: preg_match(): Unknown modifier 'b' in ... code on line ...
But it works in grep
:
$ echo 'foo/bar' | grep -P '\Qfoo/bar\E'
foo/bar
And in regex101:
https://regex101.com/r/mKI0Q9/1
But not in Perl:
$ echo 'foo/bar' | perl -ne 'print $_ if m/\Qfoo/bar\E/'
Backslash found where operator expected at -e line 1, near "m/\Qfoo/bar\"
Does \Q
and \E
are supposed to escape the delimiter?