adeeb alexander wrote:Hi all. Can any body please say what regex i should use to split the string. The string is a= "a,'b,c',d,e,'f,g,h',i" ; i need the out put in this way.
a
b,c
d
e
f,g,h
i
How can i do that i know that it is possible using regular expressions. But i have tried a lot and gone through many books. But i dint get any thing in my head. Regular expressions is like unknown language to me. Some one please help me out.
Thanks and Regards.
alexander
In plain English, a regex solution might sound like this:
split on a comma only if that comma has zero, or an even number of single quotes ahead of it:
You can then remove the single quotes from the tokens. Using this approach, you don't remove the single quotes at the same time since that will break the logic of "counting" an even (or uneven) number of quotes ahead of it.
If you are wondering how to do it in one go, then it will get (a bit?) more complicated. You would then have to use a bit of alternation:
split on comma-quote OR quote-comma OR the pattern described earlier: