Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 640
  • Last Modified:

Parsing comma delimited line using Regular Expressions

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
silentthread2k
Asked:
silentthread2k
2 Solutions
 
Chuck YetterCommented:
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
 
Todd MummertCommented:
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
 
silentthread2kAuthor Commented:
Thank you both for your help.

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

test1,test2,test3

I can use....

([^,]+)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now