Possible Duplicate:
Parsing CSV input with a RegEx in java
I have an input file in which each line has input values of string of the following form:
" ab cd " , " efgh,ijk.", 4,"lmno"
i.e.,
- The words are either in quotes or they have no quotes.
- The space before and after the start and end word respectively is not allowed.
EDIT: 3. It can have inputs just separated by commas.(abc,"Hi Mary,Joe",5)
Using .Split() in java, I need a regular expression to output this:
ab cd
efgh,ijk.
4
lmno
I tried this:
[^",]*[\",]
But this doesn’t work on "efgh,ijk."
Here is a link for regex testing: http://regexpal.com/
I need some assistance on this. Please help.
Thank you
DEMO
Regex pattern:
(?:\s*(?:\"([^\"]*)\"|([^,]+))\s*,?)+?Update for null values:
(?:\s*(?:\"([^\"]*)\"|([^,]+))\s*,?|(?<=,)(),?)+?DEMOAn example of it working, I know it’s kinda CSV Format but as long as you dont write really really weird things it’ll match all of them.
Edit, btw if you wanted us to give the code for you, don’t tell us about a regex online tester, if you do so it’s because you know how to handle regex, if you have no idea of how to do that, ask it too.