Regular Expressions Make CSV Parsing In ColdFusion So Much Easier (And Faster)

<!--- Create verbose regular expression. --->
<cfsavecontent variable="strRegex">(?x)
 
	## Every CSV "Group" consists of a field value
	## followed by an optional delimiter. This delimiter,
	## if it exists, will be either a field delimiler or
	## a line delimiter. If no delimiter exists, then we
	## are at the end of the file.
 
	## Let's get the field value. We need to consider two cases
	## in field values. Either the value is qualified or it is
	## not. According to standards, values that have an
	## embedded field or line delimiter or qualifier, MUST BE
	## contained in a qualified field.
 
	(
		## Because the qualified fields are the exception case,
		## we want to check for those first. A qualified field
		## can contain non quotes AND escaped quotes.
 
		"(?:[^"]|"")*"
 
		| ## OR
 
		## If we did not match the qualified field token, then
		## we need to check for the non-qualified field token
		## which can be zero or more characters NOT consisting
		## of any qualifier or delimiter.
 
		[^",\r\n]*
 
	)
 
	## Now that we have captured the zero+ length field value,
	## we can get the token. Remember, if we are at the end
	## of the file, the token will not exist and therefore,
	## this group must be optional (?).
 
	(
		## Comma
 
		,
 
		## OR return with optional newline.
 
		|\r\n?
 
		## OR just new line (I include this option for safer
		## text values across operating systems (but this might
		## not be necessary).
 
		|\n
	)?
 
</cfsavecontent>

For Cut-and-Paste