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 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

Related Questions

re = //?(\w+)/(\w+)/ s = '/projects/new' s.match(re) I have this regular expression which I
I have a regular expression to match a persons name. So far I have
Does anyone have a regular expression handy that will match any legal DNS hostname
What follows is a regular expression I have written to match multi-line pre-processor macros
I have this regular expression: ^\$?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$ however it is failing when i have an
I have a regular expression like this (much simplified): ^(ab)*$ And am matching against
I have a regular expression to match usernames (which functions in PHP using preg_match
I have regular expression like this: error 1|error 2|error 3|error 4|error 5 about 80
I have a regular expression to find :ABC:`hello` pattern. This is the code. format
I have a syntax highlighting function in vb.net. I use regular expressions to match

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.