Regular expression to match CSV delimiters

后端 未结 6 979
天命终不由人
天命终不由人 2020-12-17 22:39

I\'m trying to create a PCRE that will match only the commas used as delimiters in a line from a CSV file. Assuming the format of a line is this:

1,\"abcd\",         


        
6条回答
  •  离开以前
    2020-12-17 23:07

    See my post that solves this problem for more detail.

    ^(?:(?:"((?:""|[^"])+)"|([^,]*))(?:$|,))+$ Will match the whole line, then you can use match.Groups[1 ].Captures to get your data out (without the quotes). Also, I let "My name is ""in quotes""" be a valid string.

提交回复
热议问题