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

  • Home
  • SEARCH
  • 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 6016943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:03:25+00:00 2026-05-23T03:03:25+00:00

I have a simple regular expression which looks something like ([a-z]*)( +[a-z]=[0-9])* and it

  • 0

I have a simple regular expression which looks something like

([a-z]*)( +[a-z]="[0-9]")*

and it works in matching patterns like

test a="1" b="2" c="3"...

Is there any way of capturing each of the name-value pairs (e.g., a=”1″) in a separate matcher group?

As it is in the above example, I get a matcher group for (test) and only one matcher group for the 3 name-value pairs (i.e., the last one, c=”3″). I would expect 3 matcher groups, 1 for each such pair.

  • 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. Editorial Team
    Editorial Team
    2026-05-23T03:03:26+00:00Added an answer on May 23, 2026 at 3:03 am

    I would expect 3 matcher groups, 1 for each such pair.

    No, it’s two groups in total. The only way to get the key-value pairs in three groups, is by doing:

    ([a-z]*)( +[a-z]="[0-9]")( +[a-z]="[0-9]")( +[a-z]="[0-9]")
    

    You could match all key value pairs in a single group and then use a separate Pattern & Matcher on it:

    import java.util.regex.*;
    
    public class Main {
      public static void main(String[] args) throws Exception {
    
        String text = "test a=\"1\" b=\"2\" c=\"3\" bar d=\"4\" e=\"5\"";
        System.out.println(text + "\n");
    
        Matcher m1 = Pattern.compile("([a-z]*)((?:[ \t]+[a-z]=\"[0-9]\")*)").matcher(text);
    
        while(m1.find()) {
    
          System.out.println(m1.group(1));
    
          Matcher m2 = Pattern.compile("([a-z])=\"([0-9])\"").matcher(m1.group(2));
    
          while (m2.find()) {
            System.out.println("  " + m2.group(1) + " -> " + m2.group(2));
          }
        }
      }
    }
    

    which produces:

    test a="1" b="2" c="3" bar d="4" e="5"
    
    test
      a -> 1
      b -> 2
      c -> 3
    
    bar
      d -> 4
      e -> 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the simple regular expression: \{[0-9]*\} which works fine with PHP's ereg_ functions
I have a regular expression which works perfectly well (although I am sure it
i have simple regular expression: ^123$ Matches are for example 123 1234 etc. How
I have the following very simple Javascript-compatible regular expression: <script type=text/javascript id=(.+) src=([^]+)> I
I have simple HTML code with some JavaScript. It looks like: <html> <head> <script
I have a regular expression for use with awk to find any of the
I have got a question on regular expression. Though simple, I got some contracting
I have this problem which made my scratch my head: Is there a way
I would like a regular expression, of which I will use with the Python
I would like to perform a MySQL regular expression which will check a string

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.