>>> Try
>>> <<<(.)+?>>>
[quoted text clipped - 11 lines]
> Thank you! Could you please explain why this works and not the regex I
> used?
I guess Java's regular expression engine is by default greedy (most RE
engines are greedy by default). I'm guessing the first alternative, (.+?),
the '?' acts as a modifer on '+', telling it not to be greedy. That is,
instead of matching the longest possible substring, it tries to match the
shortest possible substring.
In the second alternative, instead of accepting "<<<" followed by
anything, followed by ">>>", it accepts "<<<" followed by anything except
">", followed by ">>>".
- Oliver
lordy - 13 Jul 2006 00:29 GMT
>>>> Try
>>>> <<<(.)+?>>>
[quoted text clipped - 23 lines]
>
> - Oliver
And the latter is more efficient. The first will do a lot of
backtracking given the expected input strings.
Lordy
>> <<<(.+?)>>>
>> <<<([^>]+)>>>
>Thank you! Could you please explain why this works and not the regex I used?
The first suggestion should be used, because the second one
fails to match "<<<ab<c>def>>>".
Oliver by now has explained the expressions. See also:
http://download.java.net/jdk6/docs/api/java/util/regex/Pattern.html
Moiristo - 12 Jul 2006 20:50 GMT
>>> <<<(.+?)>>>
>>> <<<([^>]+)>>>
[quoted text clipped - 6 lines]
>
> http://download.java.net/jdk6/docs/api/java/util/regex/Pattern.html
Thank you both. I knew it was something like that, but I didn't know
about modifiers in regex's; I only knew that '?' stood for 'once or not
at all'.