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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:50:01+00:00 2026-06-12T05:50:01+00:00

String input = 2012 AL REG TEXT 300535(NS); String regex = ^((\\d{4})\\s+)?((\\S+)\\s+(.+?)\\s+)\\s+((\\S+)(\\s+\\(.*?\\)))$; I want

  • 0
String input = "2012 AL REG TEXT 300535(NS)";
String regex = "^((\\d{4})\\s+)?((\\S+)\\s+(.+?)\\s+)\\s+((\\S+)(\\s+\\(.*?\\)))$";

I want to capture 2012 in a group, “AL REG TEXT” in another group, and “300535(NS)” in another group.

  • 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-12T05:50:02+00:00Added an answer on June 12, 2026 at 5:50 am

    The error is that you have an extra \\s+ right before the expected parantheses and, as @cmonkey points out, an extra \\s+ in the middle. Remove these and it works. Also, to only get the groups you mention above, add ?: to the ones you don’t want to capture:

    String input = "2012 AL REG TEXT 300535(NS)";
    String regex = "^(?:(\\d{4})\\s+)?((?:\\S+)\\s+(?:.+?))\\s+((?:\\S+)(?:\\(.*?\\)))$";
    Matcher m = Pattern.compile(regex).matcher(input);
    if (m.matches()) {
        for (int i = 1; i <= m.groupCount(); i++) {
            System.out.format("Group %d: '%s'%n", i, m.group(i));
        }
    }
    

    prints

    Group 1: '2012'
    Group 2: 'AL REG TEXT'
    Group 3: '300535(NS)'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

string input = aaaabbbccc12345677XXXXsfsfsrfsd; MessageBox.Show(Regex.Match(input, 7(?<x1>.*)s).Groups[x1].Value); That Result 7XXXXsfsfsrf OK but i want XXXX
I want to input a string through command line to bash script and output
A string 2012-03-02 representing March 2nd, 2012 is given to me as an input
I have a string input to my program of the form: con*.cc I want
Input String: June 14, 2012 - 01:00:00 UTC Output Local String: Jun 13, 2012
I have an input string as below: john is a StartDate 10\11\2012 EndDate 15\11\2012
E.g. i might have input string like below: 2012-07-23T03:30:00.000Z or 2012-06-25T13:00:00.000+08:00 For these two
I'm struggling with a regex pattern that will pull out text from a string
How do I get the required output? input string : software Company(1920 of 2012)(sb.2)(sb.3)
String input = key1=value1&key2=value2&key3=value3&key4=value4&key5=value5; How can I store the key-value pairs into a HashMap

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.