I want to be able to split a string from a repeating pattern. For exemple:
id||eq||2,id||eq||1
will give me id||eq||2 and id||eq||1
this is easy because the separator is ,. But unfortunately I can have the separator inside the splitted part:
id||eq||2,2,id||eq||1
and I would like to get id||eq||2,2 and id||eq||1
I tried something like this: (\w+\|{2}\w+\|{2}[\w,]+,?)
But it always take the first part of the next group and not the second group
id||eq||1,2,id||eq||2,1
I'm out of ideas, if some of you can help me ?
EDIT
To be more precise, I want to get an array of objects (lets call it RequestFilter[]) from an url (and the param in the url is already an array).
An object RequestFilter looks like this:
fieldwhich is a string and can only contain alphanumeric charstypewhich is an enum, can either contain only alphanumeric charsfilterwhich can be any char ( like,)
which give me this in the url: ?filter[]=field||type||filter
today I already get RequestFilter from an url, but now I have to get an array of RequestFilter. I could use any separator, but because the attribute filter can be anything there will always be a risk of conflict with it while splitting.
some more examples of strings I can have and the expected RequestFilter[]:
name||cont||pier
[{field: 'name', type: 'cont', filter: 'pier'}]
name||cont||a,id||in||2,3
[{field: 'name', type: 'cont', filter: 'pier'},{field: 'id', type: 'in', filter: '2,3'}]
id||in||2,3,4,5,address||eq||Paris,France
[{field: 'id', type: 'in', filter: '2,3,4,5'},{field: 'address', type: 'eq', filter: 'Paris,France'}]
EDIT 2
I was pretty sure it was possible to handle it with Regex but if you think it's not possible just tell me and I will try to find another way to handle it.