Regex find comma not inside quotes

前端 未结 5 1994
不思量自难忘°
不思量自难忘° 2020-12-05 07:52

I\'m checking line by line in C#

Example data:

bob jones,123,55.6,,,\"Hello , World\",,0
jim neighbor,432,66.5,,,Andy \"Blank,,1
john smith,555,77.4,         


        
5条回答
  •  长情又很酷
    2020-12-05 08:04

    Stand back and be amazed!


    Here is the regex you seek:

    (?!\B"[^"]*),(?![^"]*"\B)


    Here is a demonstration:

    regex101 demo


    • It does not match the second line because the " you inserted does not have a closing quotation mark.
    • It will not match values like so: ,r"a string",10 because the letter on the edge of the " will create a word boundary, rather than a non-word boundary.

    Alternative version

    (".*?,.*?"|.*?(?:,|$))

    This will match the content and the commas and is compatible with values that are full of punctuation marks

    regex101 demo

提交回复
热议问题