Solved

Parsing comma delimited line using Regular Expressions

Posted on 2009-05-19
3
632 Views
Last Modified: 2012-06-27
Hi,

I'm using Rad Software Regular Expression Software, to try to parse a comma delimited line.
Example input is....

test1,test2,

And this is the expression....

(,)([a-zA-Z&/0-9 .\\]{1,100})(,)

But I'm only getting "test2".
I'm not getting "test1"

I don't need a text qualifier, just a simple way to parse them.
0
Comment
Question by:silentthread2k
3 Comments
 
LVL 6

Accepted Solution

by:
Chuck Yetter earned 250 total points
ID: 24423077
Here's a method I've used to parse delimited data:

string data = "your,data,here";
char[] delimiter = { ',' };
string[] parsedData = data.Split(delimiter);

You get a string array without the headaches of regular expressions.
0
 
LVL 11

Assisted Solution

by:climbgunks
climbgunks earned 250 total points
ID: 24423091
You're only getting test2 because it's the only field that has a comma on both sides

Typically, you'd use something like ( and I don't use Rad Software, so this may be wrong ).  This works if there is not a trailing comma as well:

([^,]+)(,?)

which basically says  find any group of characters that are not commas, then possibly a comma at the end.   You could iterate through the string, searching for each successive match if you wanted or just build up longer matches:

([^,]+)(,?)([^,]+)(,?)
0
 

Author Comment

by:silentthread2k
ID: 24423165
Thank you both for your help.

Also, I found that if I have.....

test1,test2,test3

I can use....

([^,]+)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now