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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:35:08+00:00 2026-05-14T06:35:08+00:00

Response to : Regular Expression to find a string included between two characters while

  • 0

Response to : Regular Expression to find a string included between two characters while EXCLUDING the delimiters

Hi,I’m looking for a regex pattern that applies to my string including brackets:

[1,2,3,4,5] [abc,ef,g] [0,2,4b,y7]

could be anything including word,digit,non-word together or separated.

I wish to get the group between brackets by \[(.*?)\]
but what is the regex pattern that will give me the group between brackets and sub-group strings separated by commas so that the result may be following ??

Group1 : 1,2,3,4,5
 Group1: 1
 Group2: 2
 Group3: 3
 Group4: 4
 Group5: 5

Group2 : abc,ef,g
 Group1: abc
 Group2: ef
 Group3: g

etc ..

Thank you for your help

  • 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-14T06:35:09+00:00Added an answer on May 14, 2026 at 6:35 am

    I agree with @Dav that you would be best using String.Split on each square-bracketed group.

    However, you can extract all the data using a single regular expression:

    (?:\s*\[((.*?)(?:,(.+?))*)\])+
    

    Using this expression, you will have to process all the captures of each group to get all the data. As an example, run the following code on your string:

    var regex = new Regex(@"(?:\s*\[((.*?)(?:,(.+?))*)\])+");
    var match = regex.Match(@"[1,2,3,4,5] [abc,ef,g] [0,2,4b,y7]");
    
    for (var i = 1; i < match.Groups.Count; i++)
    {
        var group = match.Groups[i];
        Console.WriteLine("Group " + i);
    
        for (var j = 0; j < group.Captures.Count; j++)
        {
            var capture = group.Captures[j];
    
            Console.WriteLine("  Capture " + j + ": " + capture.Value 
                                           + " at " + capture.Index);
        }
    }
    

    This produces the following output:

    Group 1
      Capture 0: 1,2,3,4,5 at 1
      Capture 1: abc,ef,g at 13
      Capture 2: 0,2,4b,y7 at 24
    Group 2
      Capture 0: 1 at 1
      Capture 1: abc at 13
      Capture 2: 0 at 24
    Group 3
      Capture 0: 2 at 3
      Capture 1: 3 at 5
      Capture 2: 4 at 7
      Capture 3: 5 at 9
      Capture 4: ef at 17
      Capture 5: g at 20
      Capture 6: 2 at 26
      Capture 7: 4b at 28
      Capture 8: y7 at 31
    

    Group 1 gives you the value of each square-bracketed group, group 2 gives you the first item matched in each square-bracketed group and group 3 gives you all the subsequent items. You will have to look at the indexes of the captures to determine which item belongs to each square-bracketed group.

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

Sidebar

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • 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 Are you urlencode() your filename? If not, you need to. May 14, 2026 at 6:12 pm
  • Editorial Team
    Editorial Team added an answer If you open the solution file (SolutionName.sln) in a text… May 14, 2026 at 6:12 pm
  • Editorial Team
    Editorial Team added an answer How about http://www.pivotaltracker.com/. Really nice app and it used to… May 14, 2026 at 6:12 pm

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.