Title |
Test
Find
Parse Comma Delimited Strings
|
Expression |
^(?<field1>[^,]+),(?<field2>[^,]+),(?<field3>[^,]+)$ |
Description |
Example of a regular expression that can be used to parse a comma delimited string into constituent, named sub-strings. Add or remove regex subfield definitions (?<field1>[^,]+) and corresponding delimiting characters in the regular expression as necessary to accommodate the string and subfields you intend to parse. Optionally, rename the subfield names in the regular expression to more meaningful names if you are using the parsed sub-strings in a program. Replace all occurrences of the comma in the regular expression with any required alternative delimiting character. As long as the delimiting character used does not occur naturally in any of the sub-strings, you should be good-to-go. NOTE: To change the delimiter character you must replace all occurrences of the comma in the current regex (of which there are 5) with the new delimiter character. e.g. (?<field1>[^;]+); changes the delimiter character to a semi-colon for the first field. |
Matches |
Fred,Barnie,Wilma | Bob,1/1/2003,222-3333 | 100,200,300 |
Non-Matches |
Fred,Barnie,Wilma,Betty | Bob;1/1/2003;222-3333 | Tom Dick Harry |
Author |
Rating:
Not yet rated.
Jerry Schmersahl
|
Source |
|
Your Rating |
|
Title: what about quote marks
Name: peter
Date: 8/24/2007 10:11:16 AM
Comment:
This pattern completely fails the "what if there is a comma inside a quote". So eventually you're going to run into trouble--probably sooner rather than later.
Title: -1
Name: nicky
Date: 1/19/2004 12:00:00 PM
Comment:
dude, this doesn't work.