From: Adriano Rodrigues Ferreira <[EMAIL PROTECTED]> > >DB4515C,625.25,378,327,382,352,805,163,513.5,699,257.88,,,"4,503","1, > >801",805 > > > >Trying to create a regex to substitute comas with pipes, except for > >the commas between the double quotes. > > I think there is no regex which makes such a miracle. Maybe this has > to do with the fact that regex are related to context-free languages > (in language theory terms) and this kind of problem demands > context-dependency (this is what gives comma inside and outside quotes > different meanings). But I am not absolutely right about this and > besides, Perl regexes are full with extensions which probably make it > able to recognize more complex languages. But this is just > philosophical speculation.
Yeah Perl regexps are pretty unreg. I think you want something like this: s/("[^"]*"|[^,]+)|,/defined $1 ? $1 : '|'/ge; or s/("[^"]*"|.)/$1 eq ',' ? '|' : $1/ge; This assumes that to escape a doublequote inside doublequotes you double it: "this ""thing"" is just one field!","an this is the second" If you'd wanted to support "this \"thing, thong\" is just one field!","an this is the second" you'd have to use this: s/("(?:[^"\\]|\\.)*"|[^,]+)|,/defined $1 ? $1 : '|'/ge; or s/("(?:[^"\\]|\\.)*"|.)/$1 eq ',' ? '|' : $1/ge; HTH, Jenda ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]