in reply to Re^4: How to use \W in Regular Expression?
in thread How to use \W in Regular Expression?

Sachin: Just out of curiosity: when you executed the code fragment in the OP with  -W 'no, really' warnings turned on, didn't you get a warning message?

>perl -WMstrict -le
"my $str = 'i am perl: a system';
 my $query = 'perl';
 $str =~ s/$query\W+/<em>$query<\/em> \W+/ig;
 print ' Value = ' . $str;
"
Unrecognized escape \W passed through at -e line 1.
 Value = i am <em>perl</em> W+a system

This should have been a clue.

Replies are listed 'Best First'.
Re^6: How to use \W in Regular Expression?
by ikegami (Patriarch) on Dec 30, 2009 at 14:25 UTC
    He knows it's wrong. He's asking how to fix it.
      Yes, but what I was trying to point out, perhaps rather clumsily, was that the warning message, which Sachin took the trouble to insure would be generated, not only says what's wrong, but also implies how to fix it: the problematic  '\W' is an escape sequence when it's in a substitution string.