in reply to Strange backslash in regexp behaviour
The \\B in the string literal becomes \B in the resulting string.
In a regex pattern, \B means "Match except at a word boundary".
Since the \B is between an "A" and the end of the string in the first snippet, it's on a word boundary.
Since the \B is between a space and the end of the string in the second snippet, it's not on a word boundary.
You want
or$pat = "A\\\\B"; $text = /$pat/
or$pat = qr/A\\B/; $text = /$pat/
$substr = "A\\B"; $text = /\Q$substr\E/
|
|---|