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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:41:53+00:00 2026-05-21T22:41:53+00:00

I am working on parsing the user provided input for a number which belongs

  • 0

I am working on parsing the user provided input for a number which belongs to a specified pattern such as 199-234

where the

  1. first component is 1
  2. second component is 99
  3. third component is 234

The user would provide just the first few digits or the entire string. I intend to parse each of the components out. The reg-ex that I have come up with is –

Regex regex = new Regex(@"(?<first>\d)(?<second>\d{0,2})-?(?<third>\d{0,3})");
var groups = regex.Match(input);

If I provide the input 199 , the reg-ex pattern breaks them into 3 groups instead of the expected 2.
Actual result is

  1. first component is 1
  2. second component is 9
  3. third component is 9

How do I ensure that the inputs get correctly matched in this case?

  • 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-21T22:41:54+00:00Added an answer on May 21, 2026 at 10:41 pm

    Try the non-greedy version of the third group: \d{0,3}?

    Regex regex = new Regex(@"(?<first>\d)(?<second>\d{0,2})-?(?<third>\d{0,3}?)");
    var groups = regex.Match(input);
    

    It also might help (for clarity’s sake) to bind the beginning and end of the strings (^ and $)

    new Regex(@"^(?<first>\d)(?<second>\d{0,2})-?(?<third>\d{0,3}?)$");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a javascript project which involves parsing xml data. I have
I'm working on application which has workflow like this: 1.parsing home page (using HttpURLConnection,
I'm working on parsing apart Android user agents, with Python 2.5, and so far
In a program I'm working on, i need the user to input time ranges,
Working on parsing a bunch of databases put together in an older, more freewheeling
I am working on parsing a website in my application. This is the website:
Hello Android programmers, I am working on parsing a website in my application. This
I'm parsing an RSS feed with NSXMLParser and it's working fine for the title
I'm working in C#/.NET and I'm parsing a file to check if one line
I'm working on some code that deals with parsing files (mainly XML, but there

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.