Regex: This regex splits comma or semicolon separated lists of optionally quoted strings. It hand...
Posted by: RegexLib.com - Recent Patterns,
on 25 Jan 2006 |
View original | Bookmarked: 0 time(s)
Regex:
This regex splits comma or semicolon separated lists of optionally quoted strings. It handles quoted delimiters and escaped quotes. Whitespace inside quotes is preserved, outside is eaten.
I actually wrote this one over time myself, but it is so similar to Michael Ash's that I had to give credit. The only differences are the handling of whitespace and dual comma/semicolon delimiters.
*********************************************
\s*[;,]\s*(?!(?<=(?:^|[;,])\s*"(?:[^"]|""|\\")*[;,])(?:[^"]|""|\\")*"\s*(?:[;,]|$))