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 9117097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:49:39+00:00 2026-06-17T04:49:39+00:00

While extracting named data from input strings, one uses Matcher.group(String groupname) http://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html In the

  • 0

While extracting named data from input strings, one uses Matcher.group(String groupname)
http://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html

In the code below, receivedData is a hashmap that has the names of the groups. I have to iterate through it to get each name, and then call group(name).
The hashmap has to be maintained separately and can potentially, names can be entered incorrectly or get out of sync with the names in the regex, since there are a large number of them.

String patternOfData = "On (day) I ate (mealName) at (restaurant) where they had a deal (entree) for only (price)";

After compiling the Pattern,

Pattern dataExtractionPattern = Pattern.compile(patternOfData);

Matcher matcher = dataExtractionPattern.matcher(receivedDataString);
                boolean b = matcher.matches();
                if (!b) {
                    return false;
                }
                for (String key : receivedData.keySet()) {
                    String dataValue;
                    dataValue = matcher.group(key);
                    receivedData.put(key, dataValue);
                }
                return true;

Wouldnt it be better if we had both name and value being returned together? Like Map.entry group();

Or is there another way that I can do this?

  • 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-06-17T04:49:40+00:00Added an answer on June 17, 2026 at 4:49 am

    First of all, a named capturing group, newly available in Java 7, looks like (?< NAME > PATTERN ), where NAME is the name of the group and PATTERN is the pattern to match. So your example regex would be like On (?<day>\S+) I ate (?<mealName>\S+)...

    If the pattern is fixed, then there is no reason you couldn’t have a fixed list of group names. Then you could just build receivedData from scratch iterating through those group names, instead of needing it to already be set up with the correct keys.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Extracting data from XML I want to preprocess one before sending it as a
I'm facing a character discrepancy issue while extracting data from db tables. I've written
while loading getfptex(got it from CTAN) batch file ,when i'm extracting this batch file
I am encountering a problem while extracting info from a database using php+mysql and
This deals with the general problem of extracting a signed number from a string
I am facing few problems while extracting block of lines from a file. consider
I'm having difficulty extracting a single node value from a nodelist. My code takes
I have just started learning MySQL and am having trouble extracting matching flights from
While extracting a winzip file through code,Lastwritetime is changing in seconds... Actual file Lastwritetime:
I am extracting html from a website and is writing the output html to

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.