Re: regexp lookahead
- From: Jussi Piitulainen <jpiitula@xxxxxxxxxxxxxxxx>
- Date: 03 May 2006 23:40:23 +0300
Michael Powe writes:
I experimented a bit with the Java regexp lookahead functionality,
and the results don't make sense to me. The test is below.
....
Negative lookahead:
String re = "(.*)\\[(?!\\S+)\\](.*)";
The look-ahead pattern and the following pattern match at the same
position: (?!\S+) matches the empty string between the \[ and
something that _fails_ to match \S+ at that position, and that
something should start with the \]. Where can this happen?
Positive lookahead:
String re = "(.*)\\[(?=\\S+)\\](.*)";
The look-ahead pattern and the following pattern match at the same
position: (?=\S+) matches the empty string between the \[ and before
an \S+, and that \S+ should start with the \]. Where can this happen?
(Javadoc for 1.4.2 was not too helpful here, so I experimented a bit,
never having used these myself.)
.
- Follow-Ups:
- Re: regexp lookahead
- From: Michael Powe
- Re: regexp lookahead
- References:
- regexp lookahead
- From: Michael Powe
- regexp lookahead
- Prev by Date: Re: Java collections
- Next by Date: Re: Java collections
- Previous by thread: regexp lookahead
- Next by thread: Re: regexp lookahead
- Index(es):