in reply to Switch/Format to not interpret metacharacters in regex?
If what you really want to do is just look for one string in another than index is the better tool:
use strict; use warnings; my $match = "Tick F***ing Tock"; my $str = "Friday night at 11:30pm the start of a new series, 'Tick F* +**ing Tock' explores..."; if (-1 != index $str, $match) { print "..do something..\n"; }
If you really want to use a regex then use quotemeta to do the quoting for you:
use strict; use warnings; my $match = "Tick F***ing Tock"; my $str = "Friday night at 11:30pm the start of a new series, 'Tick F* +**ing Tock' explores..."; $match = quotemeta $match; if ($str =~ $match) { print "..do something..\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Switch/Format to not interpret metacharacters in regex?
by mis (Initiate) on Dec 04, 2019 at 02:09 UTC | |
by kcott (Archbishop) on Dec 04, 2019 at 06:30 UTC |