|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
RegEx for splitting comma delimited text, HOWI 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 SMOlesen wrote:
Show quoteHide quote > Hi Why should the apostrophe be removed? Or is it a typo?> > 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' Why shouldn't it split between 'false' and 'text, text, text'?Show quoteHide quote > what split expression should I use for that?? 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?? 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?? > > 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?? >> 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?? > |
|||||||||||||||||||||||