Re: Small confusion about negative lookbehind
- From: HGA03630@xxxxxxxxxxx (hiwa)
- Date: 30 May 2005 20:58:56 -0700
david.karr@xxxxxxxx wrote in message news:<1117493198.209099.208960@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...
> 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
a(?=b) There is a 'b' after me 'a' //succeeds, matches 'a' of "ab"
(?=a)b There is a 'a' of which prefix is 'b' //fails with "ab"
(?<=a)b There is a 'a' before a 'b' //succeeds, matches 'b' of "ab"
a(?<=b) There is a 'b' before a 'a' //fails with "ab"
(?<!x)b There is no 'x' before 'b' //succeeds, matches 'b' of "ab"
a(?<!x) There is no 'x' before 'a' //succeeds, matches 'a' of "ab"
> 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.
.
- References:
- Small confusion about negative lookbehind
- From: david . karr
- Small confusion about negative lookbehind
- Prev by Date: Re: retrieve list of currently running user applications in Java
- Next by Date: Re: retrieve list of currently running user applications in Java
- Previous by thread: Re: Small confusion about negative lookbehind
- Index(es):
Relevant Pages
|
|