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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:42:13+00:00 2026-05-25T11:42:13+00:00

I’m totally new with regular expressions, but am planning to master it soon. For

  • 0

I’m totally new with regular expressions, but am planning to master it soon. For now I need your help to accomplish the following:

I want to find all commas ( , ) that are between literal/quoted ( ” ) strings.

For example:

"bla bla , bla bla"

and also:

","

but not if it’s a argument delimiter, like:

Replace("abc","b","f")

Maybe it’s very simple if you know regexp, but for me not (yet) ;).

  • 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-25T11:42:14+00:00Added an answer on May 25, 2026 at 11:42 am

    You start with something like this

    "[^"]*"
    

    That’s the simplest way to match something which is quoted. You then change that to match your comma pattern.

    "[^",]*,[^"]*"
    

    But you wan’t to capture the comma so you make that a group

    "[^",]*(,)[^"]*"
    

    And then to be able to find many commas in one string you can use repetition with a non capturing group.

    "(?:[^",]*(,))+[^"]*"
    

    That should work for you, regular expression are somewhat limited and work best when used correctly. The above pattern looks for a quot, and looks for things that aren’t quotes a comma and then goes on looking. It’s based on repetition of the first group, that way it can find may commas in a string (you’ll access ’em in the Captures property of that Group when you do the match).

    var regex = new Regex("\"(?:[^\",]*(,))+[^\"]*\"");
    var m = regex.Match("a,b,c");
    m.Groups[1].Captures // <-- all commas are captured in this collection
    

    As long as the string doesn’t contain quotes itself, this will work nicely, but it’s hard to accept escape sequences within quoted strings with regex. That something they aren’t good at handling. So, as long as that fine, go with it.

    Now to the issue with the situation when you have this type of string "a","b". Scanning the string using the regex will match from left to tight and consume characters in that order, if any match is successful it cannot proceed matching it in any other way. The problem here is that a quoted string without quotes are not a successful match (if we make it a match, but ignore it we can work around this).

    We always attempt our initial derivation first but fallback to a plain quoted string which we just ignore, that way it will skip a head and not consider the middle of the string as a valid match. It’s all about making sure that state machine, that is, the regex can keep track on the opening and closing of quoted values.

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

    That’s your final solution but you have to check that Group[1] is successful because now the pattern is successful if it finds a quoted string but the capturing group Group[1] isn’t.

    var regex = new Regex("\"(?:[^\",]*(,))+[^\"]*\"|\"[^\"]*\"");
    var m = regex.Match("a,b,c");
    if (m.Groups[1].Success)
    {
        // Do your thing ;)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.