![]() |
|
Pathologically Eclectic Rubbish Lister | |
PerlMonks |
"Inverse" Pattern Matchingby hdb (Monsignor) |
on Jul 04, 2013 at 20:38 UTC ( #1042519=perlquestion: print w/replies, xml ) | Need Help?? |
hdb has asked for the wisdom of the Perl Monks concerning the following question: I am looking for a pattern in a long string where the long string contains some wildcards. Example:
The 'x' characters in the long string stands for one or two arbitrary characters in the pattern (ie ..? in regex language. The carets ^ indicate where the pattern would match: in the first place literally, in the second 'x' stands for '4', in the third 'x' is for '45' and in the last 'x' is for '12'. I could loop over the long string, replace 'x' with '..?' and then match '123456' against the resulting pattern (actually several patterns as the length varies depending on '..?' matching one or two characters) but this would be time consuming for large strings (~millions of characters) and a shame not to fully utilize Perl's matching capabilities. Is there a way to utilize Perl's regex engine in such a way that the wildcards are in the string rather than the pattern? Remark: '123456' really are arbitrary characters, no order is implied.
Back to
Seekers of Perl Wisdom
|
|