Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
Created·2022-12-16 15:30
Flavor·PCRE2 (PHP)

/
(?:'[^']*'|"[^"]*"|(\((?:[^()]++|(?1))*\))|[^'",])+
/
gm
Open regex in editor

Description

Breaks a CSV into parts, but keeps those things in quotes (single OR double), or in curved bracket together.

preg_match_all('~(?:\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|(\((?:[^()]++|(?1))*\))|[^\'",])+~s', $text, $matches)

Submitted by anonymous