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:
Long string:1234561234123x561234123x61234x34561234 ^ ^ | ^ |\ ^\ Pattern: 123456 123456 123456 123456
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: "Inverse" Pattern Matching
by LanX (Saint) on Jul 04, 2013 at 20:54 UTC | |
by hdb (Monsignor) on Jul 05, 2013 at 12:22 UTC | |
Re: "Inverse" Pattern Matching
by choroba (Cardinal) on Jul 04, 2013 at 22:32 UTC | |
by hdb (Monsignor) on Jul 05, 2013 at 12:21 UTC | |
Re: "Inverse" Pattern Matching
by Anonymous Monk on Jul 04, 2013 at 20:49 UTC | |
by hdb (Monsignor) on Jul 04, 2013 at 20:59 UTC | |
Re: "Inverse" Pattern Matching
by LanX (Saint) on Jul 05, 2013 at 12:18 UTC |