Regular Expressions 101

Community Patterns

Parse Excel CSV data

2

Regular Expression
PCRE2 (PHP >=7.3)

/
(?:,|\n|^)("(?:(?:"")*[^"]*)*"|[^",\n]*|(?:\n|$))
/
g

Description

This is the best regex I found that was able to correctly parse cells containing multiple lines (hard line breaks). Low number of steps with sufficient speed, and it doesn't require /x option either.

Source: https://gist.github.com/awwsmm/886ac0ce0cef517ad7092915f708175f

Submitted by thdoan - 14 days ago (Last modified 14 days ago)