- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Parse Comma Delimited Strings
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 (?&lt;field1&gt;[^,]+) 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. (?&lt;field1&gt;[^;]+); changes the delimiter character to a semi-colon for the first field.
Fred,Barnie,Wilma | Bob,1/1/2003,222-3333 | 100,200,300
Fred,Barnie,Wilma,Betty | Bob;1/1/2003;222-3333 | Tom Dick Harry
Author Rating: Not yet rated. Jerry Schmersahl
Your Rating
Bad Good

Enter New Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: what about quote marks
Name: peter
Date: 8/24/2007 10:11:16 AM
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
dude, this doesn't work.

Copyright © 2001-2021, | ASP.NET Tutorials