Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8013252

Regex Matcher .start and .end should be accessible by group name

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • 8
    • 7
    • core-libs
    • None
    • b91
    • Verified

      A DESCRIPTION OF THE REQUEST :
      Java 7 added support for named capturing groups to java.util.regex. This includes the new method Matcher.group(String name) as an analog to Matcher.group(int group). But there is no analog to Matcher.start(int group) or Matcher.end(int group) and it seems they can't be used knowing only the group name.

      I'd humbly request either or both of the following be added in a future version of the public API:
      (1) Methods Matcher.start(String group) and Matcher.end(String group).
      (2) A method Pattern.groupIndex(String name)

      JUSTIFICATION :
      This change would make the named group lookup as useful as the numbered group lookup.

      Currently I'm using a thin wrapper library which adds named capturing groups for Java 5 and 6: https://code.google.com/p/named-regexp/
      It's a little flimsy but it has all three of the above-suggested methods. In upgrading an application to Java 7, I thought I could eliminate the wrapper library, but it still has superior features! I use the end method by group name in a few places and can't nicely avoid it because the patterns are diabolically complicated.

            sherman Xueming Shen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: