Home All Groups Group Topic Archive Search About

RegEx for splitting comma delimited text, HOW

Author
10 May 2006 9:54 AM
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

Author
10 May 2006 10:31 AM
Göran_Andersson
SMOlesen wrote:
Show quoteHide quote
> 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'?

Show quoteHide quote
> what split expression should I use for that??
Author
10 May 2006 3:40 PM
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.....


Show quoteHide quote
"Göran Andersson" <gu***@guffa.com> wrote in message
news:%236oEnzBdGHA.4072@TK2MSFTNGP05.phx.gbl...
> 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??
Author
10 May 2006 6:28 PM
Göran_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.

SMOlesen wrote:
Show quoteHide quote
> 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.....
>
>
> "Göran Andersson" <gu***@guffa.com> wrote in message
> news:%236oEnzBdGHA.4072@TK2MSFTNGP05.phx.gbl...
>> 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??
>
>
Author
11 May 2006 5:48 AM
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



Show quoteHide quote
"Göran Andersson" <gu***@guffa.com> wrote in message
news:eLcSM%23FdGHA.3792@TK2MSFTNGP03.phx.gbl...
> 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.
>
> SMOlesen wrote:
>> 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.....
>>
>>
>> "Göran Andersson" <gu***@guffa.com> wrote in message
>> news:%236oEnzBdGHA.4072@TK2MSFTNGP05.phx.gbl...
>>> 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??
>>
Author
15 May 2006 6:27 PM
Göran_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 wrote:
Show quoteHide quote
> 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" <gu***@guffa.com> wrote in message
> news:eLcSM%23FdGHA.3792@TK2MSFTNGP03.phx.gbl...
>> 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.
>>
>> SMOlesen wrote:
>>> 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.....
>>>
>>>
>>> "Göran Andersson" <gu***@guffa.com> wrote in message
>>> news:%236oEnzBdGHA.4072@TK2MSFTNGP05.phx.gbl...
>>>> 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??
>