How do I perform a minimal character regexp match?
Example:
For the string "one two three" the regexp "o.*e" matches the entire string. However, I want a regular expression that matches the shortest substring beginning with "o" and ending with "e", that is "one" in this case (with the next match being "o thre" and not "o three").
Anyone knows? Is it at all possible?
Minimal Regexp Matches, How To?
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Re: Minimal Regexp Matches, How To?
At 10:40 2001-12-01 GMT, Andreas wrote:
>
>o[^e]*e
>
>[^e] matches anything but an e
>
Sure, this solves it for this specific problem.
I had something in general in mind.
Is there a way to do minimal matching _in_general_?
(Or can it be shown that the problem can always be solved like this?)
>
>o[^e]*e
>
>[^e] matches anything but an e
>
Sure, this solves it for this specific problem.
I had something in general in mind.
Is there a way to do minimal matching _in_general_?
(Or can it be shown that the problem can always be solved like this?)
Re: Minimal Regexp Matches, How To?
If you have only a character at the end of the expression you search for, it's always possible to do it in the above way. But in
one and one and one
searching for the shortest expression beginning with "o" and ending with "and" is not possible.
This is called "greedy" regular expression and it's the default in TextPad (as in most other editors I know).
Perl knows special regexps that match non-greedy.
So I don't think this is possible in general. So send it as an enhancement request
one and one and one
searching for the shortest expression beginning with "o" and ending with "and" is not possible.
This is called "greedy" regular expression and it's the default in TextPad (as in most other editors I know).
Perl knows special regexps that match non-greedy.
So I don't think this is possible in general. So send it as an enhancement request
