Is your question really about how to prevent $query="perl"; from matching anything in "This drink is fraperliscious!"?
$str =~ s/\b\Q$query\E\b/<em>$query<\/em>/ig;
or
$str =~ s/(?<!\w)\Q$query\E(?!\w)/<em>$query<\/em>/ig;
In reply to Re: How to use \W in Regular Expression?
by ikegami
in thread How to use \W in Regular Expression?
by Sachin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |