Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 105999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:31:39+00:00 2026-05-11T01:31:39+00:00

It is my understanding that the java.regex package does not have support for named

  • 0

It is my understanding that the java.regex package does not have support for named groups (http://www.regular-expressions.info/named.html) so can anyone point me towards a third-party library that does?

I’ve looked at jregex but its last release was in 2002 and it didn’t work for me (admittedly I only tried briefly) under java5.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:31:40+00:00Added an answer on May 11, 2026 at 1:31 am

    (Update: August 2011)

    As geofflane mentions in his answer, Java 7 now support named groups.
    tchrist points out in the comment that the support is limited.
    He details the limitations in his great answer "Java Regex Helper"

    Java 7 regex named group support was presented back in September 2010 in Oracle’s blog.

    In the official release of Java 7, the constructs to support the named capturing group are:

    • (?<name>capturing text) to define a named group "name"
    • \k<name> to backreference a named group "name"
    • ${name} to reference to captured group in Matcher’s replacement string
    • Matcher.group(String name) to return the captured input subsequence by the given "named group".

    Other alternatives for pre-Java 7 were:

    • Google named-regex (see John Hardy‘s answer)
      Gábor Lipták mentions (November 2012) that this project might not be active (with several outstanding bugs), and its GitHub fork could be considered instead.
    • jregex (See Brian Clozel‘s answer)

    (Original answer: Jan 2009, with the next two links now broken)

    You can not refer to named group, unless you code your own version of Regex…

    That is precisely what Gorbush2 did in this thread.

    Regex2

    (limited implementation, as pointed out again by tchrist, as it looks only for ASCII identifiers. tchrist details the limitation as:

    only being able to have one named group per same name (which you don’t always have control over!) and not being able to use them for in-regex recursion.

    Note: You can find true regex recursion examples in Perl and PCRE regexes, as mentioned in Regexp Power, PCRE specs and Matching Strings with Balanced Parentheses slide)

    Example:

    String:

    "TEST 123" 

    RegExp:

    "(?<login>\\w+) (?<id>\\d+)" 

    Access

    matcher.group(1) ==> TEST matcher.group("login") ==> TEST matcher.name(1) ==> login 

    Replace

    matcher.replaceAll("aaaaa_$1_sssss_$2____") ==> aaaaa_TEST_sssss_123____ matcher.replaceAll("aaaaa_${login}_sssss_${id}____") ==> aaaaa_TEST_sssss_123____  

    (extract from the implementation)

    public final class Pattern     implements java.io.Serializable { [...]     /**      * Parses a group and returns the head node of a set of nodes that process      * the group. Sometimes a double return system is used where the tail is      * returned in root.      */     private Node group0() {         boolean capturingGroup = false;         Node head = null;         Node tail = null;         int save = flags;         root = null;         int ch = next();         if (ch == '?') {             ch = skip();             switch (ch) {              case '<':   // (?<xxx)  look behind or group name                 ch = read();                 int start = cursor; [...]                 // test forGroupName                 int startChar = ch;                 while(ASCII.isWord(ch) && ch != '>') ch=read();                 if(ch == '>'){                     // valid group name                     int len = cursor-start;                     int[] newtemp = new int[2*(len) + 2];                     //System.arraycopy(temp, start, newtemp, 0, len);                     StringBuilder name = new StringBuilder();                     for(int i = start; i< cursor; i++){                         name.append((char)temp[i-1]);                     }                     // create Named group                     head = createGroup(false);                     ((GroupTail)root).name = name.toString();                      capturingGroup = true;                     tail = root;                     head.next = expr(tail);                     break;                 } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 215k
  • Answers 216k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you look at the output of the compiler in… May 12, 2026 at 11:04 pm
  • Editorial Team
    Editorial Team added an answer Do you know the Type of the control you're finding?… May 12, 2026 at 11:04 pm
  • Editorial Team
    Editorial Team added an answer Make a ACCDE copy of the DB This will Strip… May 12, 2026 at 11:04 pm

Related Questions

My understanding is that Java's implementation of regular expressions is based on Perl's. However,
I'm trying to use EventBus from Jython. Sending events to the from Jython bus
I am working on porting code from JAVA to C#, and part of the
I am trying to load big image files in Java and i am getting

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.