silentius has asked for the wisdom of the Perl Monks concerning the following question:
Much Revered Monks, I come humbly to your presence to ask for light in a regular expression issue,
I need to check whether a certain line matches any of a set of patterns.
I have: if ($line =~ $rex) { ... } where $rex = qr/^.+(s m e f|s f pl|s f).+$/;
How do I make it match the longest "or" possible? If "s f pl" is in the line I'd like that to be the match, and NOT "s f". I wrote the "or" patterns in decreasing order of length from left to right, but it is matching just "s f" even when it could match "s f pl".
Revered Monks, if you can shed any light on this, I'd be most grateful.
humbly, silentius
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: match longest sequence in an "or" RE
by Corion (Patriarch) on Sep 24, 2011 at 16:43 UTC | |
by AnomalousMonk (Archbishop) on Sep 24, 2011 at 19:23 UTC | |
by silentius (Monk) on Sep 24, 2011 at 16:54 UTC | |
|
Re: match longest sequence in an "or" RE
by AnomalousMonk (Archbishop) on Sep 24, 2011 at 19:08 UTC | |
by Corion (Patriarch) on Sep 24, 2011 at 19:41 UTC | |
by AnomalousMonk (Archbishop) on Sep 24, 2011 at 19:54 UTC | |
by JavaFan (Canon) on Sep 24, 2011 at 22:04 UTC | |
|
Re: match longest sequence in an "or" RE
by Anonymous Monk on Sep 24, 2011 at 16:47 UTC | |
by AnomalousMonk (Archbishop) on Sep 24, 2011 at 19:13 UTC | |
|
Re: match longest sequence in an "or" RE
by Khen1950fx (Canon) on Sep 25, 2011 at 00:49 UTC |