in reply to pattern matching with substring containing special character
Replace the Xs with a character class match [ABCD] then use the resulting string as the match string:
use strict; use warnings; my $match = "ABCDABCDXBCDABCXABCDXXCDABXD"; my $str = "ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD"; $match =~ s/x/[abcd]/ig; print "Matched $1\n" if $str =~ /($match)/i;
Prints:
Matched ABCDABCDABCDABCDABCDABCDABCD
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: pattern matching with substring containing special character
by Anonymous Monk on Mar 03, 2011 at 01:36 UTC |