in reply to quick question about parenthesis and regular expressions
One thing of note is that $1 will never match absorbs nor absorbed, as as it will match absorb first, the regex engine will consider the regex a success and stop. if on the other hand you want to match absorbed or absorbs you might want to change the order of the alternation around, so that the last thing it attempts to match is absorb. or for less backtracking you might try something like:
$word =~ /(absorb(?:s|ed)?)/i; print $1;
updated:added the ? as per ysth below. ysth++ for catching my oversight.
-enlil
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: quick question about parenthesis and regular expressions
by ysth (Canon) on Nov 04, 2003 at 10:15 UTC | |
|
Re: Re: quick question about parenthesis and regular expressions
by cranberry13 (Beadle) on Nov 04, 2003 at 12:31 UTC | |
by jreades (Friar) on Nov 04, 2003 at 13:32 UTC | |
by tilly (Archbishop) on Nov 04, 2003 at 18:49 UTC | |
by Roy Johnson (Monsignor) on Nov 04, 2003 at 18:08 UTC |