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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:56:49+00:00 2026-05-23T12:56:49+00:00

why regex return multi value for the match? See the following code, it should

  • 0

why regex return multi value for the match?

See the following code, it should only return one result. why there are two?

e.g 
Match m = Regex.Match("[Red] #,0.00 \"Ex\"", @"^\[(RED|GREEN|ORANGE)\]", RegexOptions.IgnoreCase);

            if (m.Success)
            {
                Console.WriteLine(m.Groups.Count);    
                Console.WriteLine(m.Groups[0].Value);
                Console.WriteLine(m.Groups[1].Value);
            }
            else
                Console.WriteLine("No match");

========Result===============
2
[Red]
Red
Press any key to continue . . .
  • 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-23T12:56:49+00:00Added an answer on May 23, 2026 at 12:56 pm

    There is a single match m, which has a single capturing group. m.Groups[0] is always the entire match. m.Groups[1] is the first capture, etc..

    If you want to see all matches, you can do this:

    foreach (Match m in regex.Matches (input))
       Console.WriteLine (m.Value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I match the following string? http://localhost:8080/MenuTest/index.action The regex should return true if
In Python compiled regex patterns have a findall method that does the following: Return
Can some recommend a regex to return the value when an item is selected
I spent lot time figuring out a simple regex to return a group (only
Given the code: import clr clr.AddReference('System') from System.Text.RegularExpressions import * def ReplaceBlank(st): return Regex.Replace(
var ssn = 123-45-6789; What is the javascript regex to return only the numeric
Is there a simple way to return regex matches as an array? Here is
I have the following in C#: public static bool IsAlphaAndNumeric(string s) { return Regex.IsMatch(s,
I have the following regex in c#: return Regex.Replace(str, [^a-zA-Z0-9_.-]+, , RegexOptions.Compiled); Valid characters
I'm constructing a regex that is looking for dates. I would like to return

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.