Reputation: 13507
Say I have the following, as input:
Tonic,Love,(Original,Mix),house,dance,ton!c
Here are the rules I am trying to get:
I have the following regex right now:
#([\(?.*?\)])|(.*?),#
I end up with results like this:
Tonic
Love
(Original
Mix)
house
dance
It's the same as splitting by the comma, except I have lost the last keyword ton!c
. I do not require this to all happen in one regex, but it is preferred.
Upvotes: 1
Views: 124
Reputation: 2983
Try
"(\([^)]+\))|([^(][^,]*)(,(\([^)]+\))|([^(][^,]*))*"
This catches all groups at once.
Upvotes: 0
Reputation: 33908
You could split on:
/,(?![^(]*\))/
or match all with:
/\([^)]*\)|[^,()]*/
at least for your examples.
I.e:
$array = preg_split('/,(?![^(]*\))/', $string);
Upvotes: 1