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

The Archive Base Latest Questions

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

I have a regular expression to match 2 different number formats: \=(?[0-9]+)\?|\+(?[0-9]+)\? This should

  • 0

I have a regular expression to match 2 different number formats: \=(?[0-9]+)\?|\+(?[0-9]+)\?

This should return 9876543 as its Value for ;1234567890123456?+1234567890123456789012345123=9876543?
and ;1234567890123456?+9876543? What I would like is to be able to return another value along with the matched ‘Value’.

So, for example, if the first string was matched, I’d like it to return:

Value: 9876543 Format:  LongFormat

And if matched in the second string:

Value: 9876543 Format:  ShortFormat

Is this possible?

  • 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-11T07:40:00+00:00Added an answer on May 11, 2026 at 7:40 am

    Another option, which is not quite the solution you wanted, but saves you using two separate regexes, is to use named groups, if your implementation supports it.

    Here is some C#:

    var regex = new Regex(@'\=(?<Long>[0-9]+)\?|\+(?<Short>[0-9]+)\?'); string test1 = ';1234567890123456?+1234567890123456789012345123=9876543?'; string test2 = ';1234567890123456?+9876543?';  var match = regex.Match(test1); Console.WriteLine('Long: {0}', match.Groups['Long']);     // 9876543 Console.WriteLine('Short: {0}', match.Groups['Short']);   // blank match = regex.Match(test2); Console.WriteLine('Long: {0}', match.Groups['Long']);     // blank Console.WriteLine('Short: {0}', match.Groups['Short']);   // 9876543 

    Basically just modify your regex to include the names, and then regex.Groups[GroupName] will either have a value or wont. You could even just use the Success property of the group to know which matched (match.Groups[‘Long’].Success).

    UPDATE: You can get the group name out of the match, with the following code:

    static void Main(string[] args) {     var regex = new Regex(@'\=(?<Long>[0-9]+)\?|\+(?<Short>[0-9]+)\?');     string test1 = ';1234567890123456?+1234567890123456789012345123=9876543?';     string test2 = ';1234567890123456?+9876543?';      ShowGroupMatches(regex, test1);     ShowGroupMatches(regex, test2);     Console.ReadLine(); }  private static void ShowGroupMatches(Regex regex, string testCase) {     int i = 0;     foreach (Group grp in regex.Match(testCase).Groups)     {         if (grp.Success && i != 0)         {             Console.WriteLine(regex.GroupNameFromNumber(i) + ' : ' + grp.Value);         }         i++;     } } 

    I’m ignoring the 0th group, because that is always the entire match in .NET

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

Sidebar

Ask A Question

Stats

  • Questions 97k
  • Answers 97k
  • 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 I have yet to see a satisfactory solution for this… May 11, 2026 at 7:29 pm
  • Editorial Team
    Editorial Team added an answer If you're using the standard Twitter feed web code for… May 11, 2026 at 7:29 pm
  • Editorial Team
    Editorial Team added an answer Short Answer: You just need to move your dataaccess layer… May 11, 2026 at 7:29 pm

Related Questions

I currently use 3 different regular expressions in one preg_match, using the or sign
I'm looking for a routine that will format a string of numbers as a
I have a field on a form that takes the following values: -1, 2-10,
I have a URL , and I'm trying to match it to a regular

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.