johnnywang has asked for the wisdom of the Perl Monks concerning the following question:
only matches the first two elements, and gives:use strict; my @input = ("A/B/C/D/E/F/", "A/B/C/D/","A/B/C/D","A/B/C/", "A/B/C","A +/B","A"); foreach (@input){ print "$1\n" if m|((?:\w+/){4})|; }
A/B/C/D/ A/B/C/D/
I'd like to have a regex that matches all elements in the input, i.e., match up to level 4, and also make the "/" at the end optional. Desired output:
What's the best way? Thanks.A/B/C/D/ A/B/C/D/ A/B/C/D A/B/C/ A/B/C A/B A
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex greedy range
by ikegami (Patriarch) on Sep 16, 2004 at 23:34 UTC | |
by Aristotle (Chancellor) on Sep 16, 2004 at 23:55 UTC | |
|
Re: regex greedy range
by johnnywang (Priest) on Sep 16, 2004 at 23:50 UTC | |
by ikegami (Patriarch) on Sep 16, 2004 at 23:55 UTC | |
|
Re: regex greedy range
by Aristotle (Chancellor) on Sep 16, 2004 at 23:19 UTC | |
by ikegami (Patriarch) on Sep 16, 2004 at 23:40 UTC | |
by Aristotle (Chancellor) on Sep 16, 2004 at 23:47 UTC |