in reply to regex finding shortest string containing n of $c
in other words, don't forget the trailing non-x caharacters to lengthen the string.n = 1 - x 2 - xx 3 - xxx. 4 - xxx.x.... 5 - xxx.x.....x......
A regex to capture these strings is
Update: With the problem redefined, the new regex should be retooled to use parsimonious quantifiers to find the shortest strings:my $regex = '\A' . ('[^x]*x' x $n) . '[^x]*'; $foo =~ m{ ($regex) }xms; # PBP orthodoxy :)
Here I have also left off the last piece of the regex, as it is a noop.my $regex = '\A' . ('[^x]*?x' x $n);
-Mark
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex finding longest string containing n of $c
by xipho (Scribe) on Sep 01, 2005 at 04:10 UTC | |
by GrandFather (Saint) on Sep 01, 2005 at 04:18 UTC | |
by xipho (Scribe) on Sep 01, 2005 at 05:01 UTC |