RegEx for splitting comma delimited text, HOW

S

SMOlesen

Hi

I need to split a comma delimited text, however if the comma is between ' '
then no split should occur

ie:

Class.Value, 'true' , 'some text', 'false', 'text, text, text'

should split into:

Class.Value
'true'
'some text
'false', 'text, text, text'

what split expression should I use for that??

TIA

Søren
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

SMOlesen said:
Hi

I need to split a comma delimited text, however if the comma is between ' '
then no split should occur

ie:

Class.Value, 'true' , 'some text', 'false', 'text, text, text'

should split into:

Class.Value
'true'
'some text

Why should the apostrophe be removed? Or is it a typo?
'false', 'text, text, text'

Why shouldn't it split between 'false' and 'text, text, text'?
 
S

SMOlesen

Sorry, it was a typo, it should split into:

Class.Value
'true'
'some text'
'false'
'text, text, text'

ie. it shouldn't split on comma if the comma is between two apostrophes....

..NET regular expression.....
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Make a pattern that matches one item, something like
"(?:([^,]+|'[^']*')", and use the Matches method to get a collection of
Match items that each contains one item.
 
S

Søren M. Olesen

Hi Göran

Doesn't seem to solve the problem, if I look at the matches I get:

Class.Value
'true'
'some text'
'false'
'text
text
text'

wouldn't I have to use som king of negative lookbehind??

Regards,

Søren



Göran Andersson said:
Make a pattern that matches one item, something like "(?:([^,]+|'[^']*')",
and use the Matches method to get a collection of Match items that each
contains one item.
Sorry, it was a typo, it should split into:

Class.Value
'true'
'some text'
'false'
'text, text, text'

ie. it shouldn't split on comma if the comma is between two
apostrophes....

.NET regular expression.....
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

When I look at the pattern I gave you, I see that the parantheses
doesn't match, so it won't be usable. How did the pattern look that you
used?

I think that just disallowing apostrophes in the first set will fix it:

"([^',]+|'[^']*')"

Søren M. Olesen said:
Hi Göran

Doesn't seem to solve the problem, if I look at the matches I get:

Class.Value
'true'
'some text'
'false'
'text
text
text'

wouldn't I have to use som king of negative lookbehind??

Regards,

Søren



Göran Andersson said:
Make a pattern that matches one item, something like "(?:([^,]+|'[^']*')",
and use the Matches method to get a collection of Match items that each
contains one item.
Sorry, it was a typo, it should split into:

Class.Value
'true'
'some text'
'false'
'text, text, text'

ie. it shouldn't split on comma if the comma is between two
apostrophes....

.NET regular expression.....


SMOlesen wrote:
Hi

I need to split a comma delimited text, however if the comma is between
' ' then no split should occur

ie:

Class.Value, 'true' , 'some text', 'false', 'text, text, text'

should split into:

Class.Value
'true'
'some text
Why should the apostrophe be removed? Or is it a typo?

'false', 'text, text, text'
Why shouldn't it split between 'false' and 'text, text, text'?

what split expression should I use for that??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top