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

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

Re: [Regexp] Baffling behavior


From: Wes Biggs
Subject: Re: [Regexp] Baffling behavior
Date: Sun, 27 Apr 2003 18:15:48 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312

Kenneth Ölwing wrote:
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???

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);

Cheers

Wes





reply via email to

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