regex to parse csv

前端 未结 3 555
独厮守ぢ
独厮守ぢ 2021-01-19 18:51

I\'m looking for a regex that will parse a line at a time from a csv file. basically, what string.readline() does, but it will allow line breaks if they are within double q

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-19 19:33

    Using regex to parse CSV is fine for simple applications in well-controlled CSV data, but there are often so many gotchas, such as escaping for embedded quotes and commas in quoted strings, etc. This often makes regex tricky and risky for this task.

    I recommend a well-tested CSV module for your purpose.

    --Edit:-- See this excellent article, Stop Rolling Your Own CSV Parser!

提交回复
热议问题