RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Parsing VB Strings (or csv qualified strings)
Expression
((?:(?:"[^"]*")|('[^\r]*)(\r\n)?)*)([\s]*[,]|$) {CHANGED TO) (?<![\"\w\d\s])[\s]*(?:"((?:[^\"]|[\"]{2})*)"|([\w\d\s]+))[\s]*(?=[\,]|[\r\n]+|$)
Description
I started out looking for a way to propertly parse delimited CSV text. Everything that I tried on my own was not doing what I wanted it to do, so I borrowed one from someone here and customized it a bit to get pretty close to what I wanted (see ORIGIONAL MESSAGE below). Ultimately though, I still needed more functionality, so I started over, and came up with this. It actually does a very good job of actually parsing columns from the CSV text. I use Regex Replace( csvText, "[$1$2]" ) to actually see the column content, but there are many other ways (obviously). ORIGIONAL MESSAGE: ____________________________________________________ I was having trouble parsing fields from csv files due to the string qualifiers, when I came across a regex posted by Tom Svensson. It didn't quite meet my needs though because it was parsing the substrings (escaped quotes) as seperate results. This one will actually parse the entire string out, with it's escaped quote portion. None the less, thank you Tom Svensson for your help!
Matches
"a""b""c", "d""e""f", JHI, 234 (pulls: a""b""c and d""e""f and JHI 234)
Non-Matches
asd"
Author Rating: Not yet rated. David Oldfield
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

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: Have a look at my regex
Name: Sven Jacobs
Date: 10/19/2006 9:39:00 AM
Comment:
Have a look at my regex (http://regexlib.com/REDetails.aspx?regexp_id=1520). It does the same job but is more compact. Just replace all ";" in my regex with "," to change the separator.


Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials