Solved

Parsing comma delimited line using Regular Expressions

Posted on 2009-05-19
3
637 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Suggested Courses

734 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