bug-classpath
[Top][All Lists]
Advanced

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

[Bug classpath/26166] Matcher.find mis-behaviour


From: kaz at maczuka dot gcd dot org
Subject: [Bug classpath/26166] Matcher.find mis-behaviour
Date: 8 Feb 2006 11:13:49 -0000


------- Comment #5 from kaz at maczuka dot gcd dot org  2006-02-08 11:13 -------
Before implementing this new syntax, could someone explain this
strange behavior of Sun's JDK?  The source of W.java used here
is attached below.

bash$ java -DFIND=1 W 'b' '[^b]'
false
bash$ java -DFIND=1 W 'b' '[^b[b]]'
true
G0 = b
bash$ java -DFIND=1 W 'b' '[^b[b]b]'
false
bash$ java -DFIND=1 W 'b' '[^b[b]b[b]]'
true
G0 = b
bash$ java -DFIND=1 W 'b' '[^b[b]b[b]b]'
false
bash$ java -DFIND=1 W 'b' '[^[b]]'
true
G0 = b
bash$ java -DFIND=1 W 'b' '[^[b]b]'
false
bash$ java -DFIND=1 W 'b' '[^[b]b[b]]'
true
G0 = b
bash$ java -DFIND=1 W 'b' '[^[b]b[b]b]'
false
bash$ cat W.java
import java.util.regex.*;
public class W {
  public static void main(String[] args) throws Exception {
    int flags = 0;
    boolean find = (System.getProperty("FIND") != null);
    if (System.getProperty("CASE_INSENSITIVE") != null) {
      flags |= Pattern.CASE_INSENSITIVE;
    }
    Pattern p = Pattern.compile(args[1], flags);
    Matcher m = p.matcher(args[0]);
    boolean b = (find ? m.find() : m.matches());
    System.out.println(b);
    if (b) {
      int groups = m.groupCount();
      for (int i = 0; i <= groups; i++) {
        System.out.println("G" + i + " = " + m.group(i));
      }
    }
  }
}

I assume

  [^X[Y][Z]] means (not X) or Y or Z
     whrere X must not contain a subclass enclosed by [].

  [^[X]] and [^X[Y]Z] are invalid expressions whose matching results are
  meaningless,  although Sun's JDK neglects the checking of validity.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26166





reply via email to

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