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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:00:29+00:00 2026-06-15T21:00:29+00:00

I have a regex pattern defined as var pattern = ,(?=(?:[^\]*\[^\]*\)*(?![^\]*\)); and I am

  • 0

I have a regex pattern defined as

var pattern = ",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))";

and I am trying to split some CSV like strings to get fields

Some example strings that WORK with this regex are

_input[0] = ""; // expected single blank field
_input[1] = "A,B,C"; // expected three individual fields
_input[2] = "\"A,B\",C"; // expected two fields 'A,B' and C
_input[3] = "\"ABC\"\",\"Text with,\""; // expected two fields, 'ABC"', 'Text with,'
_input[4] = "\"\",ABC\",\"next_field\""; // expected two fields, '",ABC', 'next_field'

However, this is not working

_input[5] = "\"\"\",ABC\",\"next_field\"";

I am expecting three fields

'"', 'ABC"', 'next_field'

But I am getting two fields

'"",ABC', 'next_field'

Can anybody help with this regex?

I think the strange part is that the second column doesn’t have quotes at the start and end of the value, just at the end. So the first column’s value is empty, and the second column is ABC”

Thanks,
Rob

  • 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-06-15T21:00:31+00:00Added an answer on June 15, 2026 at 9:00 pm

    I think you need to be even more specific about what your logic is in terms of how the double quotes should be treated, as it appears that your requirements conflicts with each other.

    My quick version that I think comes closest to what you are trying to achieve is this (please note 1) The missing escaping of double quotes, because I am using an external tool to validate the regex, and 2) I have changed how to retrieve the matched values, see the bottom for an example):

    (?<Match>(?:"[^"]*"+|[^,])*)(?:,(?<Match>(?:"[^"]*"+|[^,])*))*
    

    It has the following logic:

    • If there is a double quote, then include everything in it, until an end double quote is hit.
    • When reaching an end double quote, double quotes following immediately after will also be included.
    • If the next character is anything but a comma, it is included, and the above is tested again.
    • If it is a comma, the current match is concluded and a new one begins after the comma.

    The above logic conflicts with what you expect from index 4 and 5 however, because I get:

    [4] = '""' and 'ABC","next_field"'
    [5] = '"""' and 'ABC","next_field"'
    

    If you could point out why the above logic is wrong for your needs/expectations, I’ll edit my answer with a fully working regex.

    To retrieve your values, you could do it like this:

    string pattern = @"(?<Match>(?:""[^""]*""+|[^,])*)(?:,(?<Match>(?:""[^""]*""+|[^,])*))*";
    
    string[] testCases = new[]{
      @"",
      @"A,B,C",
      @"A,B"",C",
      @"ABC"",""Text with,",
      @""",ABC"",""next_field""",
      @""""",ABC"",""next_field"""
    };
    
    foreach(string testCase in testCases){
      var match = System.Text.RegularExpressions.Regex.Match(testCase, pattern);
      string[] matchedValues = match.Groups["Match"].Captures
        .Cast<System.Text.RegularExpressions.Capture>()
        .Select(c => c.Value)
        .ToArray();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got this regex pattern that works with my current apache log format:
I have been trying to create a regular expressions pattern that matches any reference
I have a regex pattern that searches for words in a text file. How
I have a regex pattern for URL's that I use to check for links
I have a Regex pattern that matches data I need to parse exactly as
I'm struggling to get this working. I have a regex pattern as: .*(${.*}).* And
I have developed a UI that allows users to define a regex pattern and
I have some function that uses split, but I want the separator to be
I need some help about RegExp in AS3. I have a simple pattern :
I have this regex that checks for a 5 digit number ^\d{5}$ How do

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.