Skip to content

Behaviour of calling Matcher#end after the last match doesn't match java.util.regex #201

Description

@cushon

This may be related to #200

public class Repro {
  public static void main(String[] args) {
    {
      System.err.println("re2j");
      var p = com.google.re2j.Pattern.compile("foo");
      var m = p.matcher("foobar");
      while (m.find()) {
        System.err.println(m.start());
      }
      System.err.println(m.end());
    }
    {
      System.err.println("java.util.regex");
      var p = java.util.regex.Pattern.compile("foo");
      var m = p.matcher("foobar");
      while (m.find()) {
        System.err.println(m.start());
      }
      System.err.println(m.end());
    }
  }
}
re2j
0
3
java.util.regex
0
Exception in thread "main" java.lang.IllegalStateException: No match found
	at java.base/java.util.regex.Matcher.checkMatch(Matcher.java:1850)
	at java.base/java.util.regex.Matcher.end(Matcher.java:562)
	at Repro.main(Repro.java:19)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions