Small confusion about negative lookbehind
- From: david.karr@xxxxxxxx
- Date: 30 May 2005 15:46:38 -0700
I'm writing a small test program to illustrate several aspects of
regular expressions. In the section illustrating "lookaround"s, I
found something I didn't understand. My testing is with JDK 1.4.2.
My candidate string is "ab".
The expressions I'm testing this string against are the following,
which also lists whether the string matched or not
a(?=b) // succeeds
(?=a)b // fails
(?<=a)b // succeeds
a(?<=b) // fails
(?<!x)b // succeeds
a(?<!x) // succeeds(!)
Looking at these, I first wonder what exactly is the semantic
difference between a "lookbehind" and "lookahead" construct. The
syntactic difference is obvious, but I find the question of why pattern
1 succeeds and pattern 2 fails is a little hazy. The one that really
bothers me, however, is pattern 6. Despite the lack of clarity I have
in how this is supposed to work, I was pretty certain that this pattern
would fail.
I could use some clarification of these constructs.
.
- Follow-Ups:
- Re: Small confusion about negative lookbehind
- From: hiwa
- Re: Small confusion about negative lookbehind
- From: Lasse Reichstein Nielsen
- Re: Small confusion about negative lookbehind
- Prev by Date: Re: [OT] Re: public static final const primitives?
- Next by Date: Re: Small confusion about negative lookbehind
- Previous by thread: Connecting with an applet throw a proxy
- Next by thread: Re: Small confusion about negative lookbehind
- Index(es):
Relevant Pages
|