in reply to Unrecognized escape \Q passed through in regex
\Q and \E don't work inside interpolations. They only work in regexp literals (m/here/, s/here// and qr/here/). Solutions:
and# Text. $text = 'Renata'; $window =~ /\b\Q$text\E\b/ism
and# Uncompiled regexp. $text = 'Renata'; $regexp = '\\b' . quotemeta($text) . '\\b'; $window =~ /$regexp/ism
# Compiled regexp. $regexp = qr/\b\QRenata\E\b/ism; $window =~ $regexp
Note:
The s modifier is useless if you don't use ".".
The m modifier is useless if you don't use "^" or "$".
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Unrecognized escape \Q passed through in regex
by Articuno (Beadle) on Jan 26, 2006 at 18:39 UTC | |
by ikegami (Patriarch) on Jan 26, 2006 at 18:52 UTC | |
by Articuno (Beadle) on Jan 26, 2006 at 19:13 UTC | |
by ikegami (Patriarch) on Jan 26, 2006 at 19:31 UTC | |
by Articuno (Beadle) on Jan 26, 2006 at 19:57 UTC | |
Re^2: Unrecognized escape \Q passed through in regex
by merlyn (Sage) on Jan 27, 2006 at 03:45 UTC | |
by tye (Sage) on Jan 27, 2006 at 04:00 UTC | |
by ikegami (Patriarch) on Jan 27, 2006 at 05:21 UTC |
In Section
Seekers of Perl Wisdom