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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:01:57+00:00 2026-05-18T20:01:57+00:00

I have a large Regular Expression I use for parsing my own file format

  • 0

I have a large Regular Expression I use for parsing my own file format similar to lua. This works fine, except somehow numbers inside quotes get matched twice even though split shouldn’t return overlapping results. I’ve simplified it down to this console app. Any ideas?

static void Main(string[] args)
{
    string pattern = "(\r\n)|(\"(.*)\")"; // Splits at \r\n and anything in "quotes"

    string input = "\"01\"\r\n" + // "01"
                   "\"02\"\r\n" + // "02"
                   "\"03\"\r\n";  // "03"

    string[] results = Regex.Split(input, pattern );
    foreach (string result in results )
    {
            //This just filters out the split \r\n and empty strings in results
            if (string.IsNullOrWhiteSpace(result) == false) 
                Console.WriteLine(result);
    }
    Console.ReadLine();
}

Returns:

"01"
01
"02"
02
"03"
03
  • 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-18T20:01:58+00:00Added an answer on May 18, 2026 at 8:01 pm

    From the documentation:

    If capturing parentheses are used in a Regex.Split expression, any captured text is included in the resulting string array. For example, splitting the string ” plum-pear” on a hyphen placed within capturing parentheses adds a string element that contains the hyphen to the returned array.

    You have two sets of capturing parenthesis, one inclusive of the quotes and one exclusive. These return the strings you are seeing.

    Note that the pattern for RegEx.Split isn’t supposed to match the desired results, it’s supposed to match the delimiters. A quoted string is usually not a delimiter.

    Also, your results seem very odd, because you’ve used a greedy match. Apparently the requirement “The input string is split as many times as possible.” makes matching non-greedy for the entire operation.

    Overall, I’d say you’re using the wrong tool. Regular expressions are, depending on implementation, incapable of dealing with nested groupings or extremely inefficient. A simple DFA should work much better and never need more than a single scan.

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

Sidebar

Related Questions

No related questions found

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.