Solved

Parsing comma delimited line using Regular Expressions

Posted on 2009-05-19
3
630 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…

757 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

20 Experts available now in Live!

Get 1:1 Help Now