in reply to Regexp, match the nearest verb.
Don't be greedy! No, really. The portion of your regexp (.|\n)* (note that you incorrectly have a close brace } instead of a close parenthesis ) there!) matches the longest stretch it can.
The solution? Ask for a non-greedy match (see perlre for details of *?): replace (.|\n)* with (.|\n)*?, and the shortest match (for which the continuation of the regexp matches) will be returned. Also, you may wish to consider using various regexp modifiers if your string contains newlines, instead of enclosing them as .|\n.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Regexp, match the nearest verb.
by bmal (Novice) on Dec 27, 2001 at 13:52 UTC | |
by ariels (Curate) on Dec 28, 2001 at 17:55 UTC |