Solved

Parsing comma delimited line using Regular Expressions

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…

630 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