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

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

Re: [Regexp] Baffling behavior


From: Kenneth Ölwing
Subject: Re: [Regexp] Baffling behavior
Date: Sun, 27 Apr 2003 21:44:03 -0400

> As you surmise, "isMatch" assumes anchoring on both ends.  Read as "is
> the whole input a match"?
>
> For the behavior you want, you should use:
>
> System.out.println(new RE("abc").getMatch("xabcx") != null);

Aha. Ok, got it.

It is a bit counter-intuitive however, don't you think? I interpreted the
'isMatch()' as a shortcut for the expression above, obviously wrongly. While
the doc wording is as you say, it could probably be clearer to avoid future
mishaps. And maybe there should be a convenience method for how I tried to
use it? Hmm, or maybe this should be a configurable option among the
RESyntax() stuff, or in the cflags...?

Also, arguably, this behavior could even be said to be 'wrong',
perhaps...I'm not sure there's such a thing as a 'formal' regexp definition
:-), but IMHO I'd say that:

"abc" is a regexp. "^abc$" is another regexp.. They are not the same regexp
however and can never be - i.e. there should never be something like
'assumed anchoring'. Again, IMHO of course.

But hey, I understand that this is not likely to change for backward compat,
of course. And the JDK 1.4 String.matches() method also works the same so
there is some order in the universe. I'll try the same technique you
describe there, to make sure I get my head on straight - just need to know
the rules and remember them.

Well, just some $0.02 suggestions. Thanks for responding,

ken1




reply via email to

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