Regular Expressions 101

Enterprise

Community Library

Community Library Entry

0

Regular ExpressionOpen Workspace

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

Description
Created·2022-12-16 15:30
Type·Match
Flavor·PCRE2 (PHP)

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
Open Workspace