0

I need make split for commas on a String. But I need ignore commas inside the text fields

Input example:

'Field1','Field2','Field3, this field, has, multiples commas','Field4'

Output that I want:

'Field1'
'Field2'
'Field3, this field, has, multiples commas'
'Field4'

Output that I got:

'Field1'
'Field2'
'Field3
 this field,
 has,
 multiples commas'
'Field4'

Can some one help me?

brbrbr
  • 157
  • 3
  • 17

1 Answers1

1
,(?=(?:[^']*'[^']*')*[^']*$)

You can split on this.See demo.

https://regex101.com/r/cD5jK1/10

vks
  • 63,206
  • 9
  • 78
  • 110
  • This regex works on demo... But when i put it on split() method i got java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 8. – brbrbr Oct 27 '15 at 18:49
  • Now its do split inside of the field3, and not between field3 and field4 =( – brbrbr Oct 28 '15 at 11:42
  • @Roqueirow see demo.it is working as expected – vks Oct 28 '15 at 17:12