Reputation: 3897
I wanted to split a text in Scala with ,
delimiter but don't split when the ,
is in parentheses but extract the ,
and ignore the parentheses, for example to split the following:
one, two (,) three
I should get an array containing:
`one`
`two , three`
Thank you in advance
Upvotes: 1
Views: 168
Reputation: 67968
(?![^)()]*\)),|\((?=,)|(?<=,)\)
You can try this. See demo: http://regex101.com/r/kM7rT8/2
You will have to join the last three contents of list to get the second match.
Upvotes: 1
Reputation: 784948
You can use this lookaround based regex:
(?<!\)), *(?!\))
In Java:
(?<!\\)), *(?!\\))
It will break example input into:
one
two (,) three
Upvotes: 1