gnu-regexp-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Regexp] Baffling behavior


From: Kenneth Ölwing
Subject: [Regexp] Baffling behavior
Date: Sun, 27 Apr 2003 20:57:29 -0400

Being an experienced Perl user, I got a result when using the gnu.regexp
classes that completely pulled the rug from under me.

In Perl, the following prints '1', i.e. true because it matches:

    print "xabcx" =~ /abc/;

No surprise there. But:

    System.out.println(new RE("abc").isMatch("xabcx"));

prints 'false'. Huh???

Actually, using the JDK 1.4 built in regex classes does the same
thing...still surprising to me. Haven't tried any other packages so far...

It seems to me to implicitly assume anchoring on both ends. But if it should
be anchored, I'd prefer to write that myself, i.e. using the regexp '^abc$'.
As to how it works now, how do I tell it to actually not use anchoring, and
act as Perl does? A naive way is obviously '.*abc.*' but this is horrible
performance wise with gnu.regexp classes. Probably not noticeable normally,
but it gives exponential time and memory consumption with, perhaps, abnormal
input. Sun's classes gives a linear curve.

So what gives? Is there a perfectly rational explanation that I'm completely
missing here...???

Thanks,

ken1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]