AriefFikhrie
AriefFikhrie

Reputation: 33

Regex to matches multiple string

need help to separate this string

value-filter-29[]=Test+1,Test+2,Test+2&+3&value-filter-43[]=Last+30+Days&value-filter-11[]=Testing+number

into this

already tried with regex (?:)(value-filter-\d+\[\]=.+?)(&|$)

and for the first match it will only take value-filter-29[]=Test+1,Test+2,Test+2 without &3

Is there any way to achieve this using regex?

Upvotes: 0

Views: 82

Answers (2)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627341

You can use the following regex:

\&(?=value)

It will split at every & that is followed by value. You can fine-tune this look-ahead later. Looking at the current ouput, you might want to add -filter-: \&(?=value-filter-).

See demo

Output:

value-filter-29[]=Test+1,Test+2,Test+2&+3
value-filter-43[]=Last+30+Days
value-filter-11[]=Testing+number

Upvotes: 1

Avinash Raj
Avinash Raj

Reputation: 174826

You need to use a positive lookahead assertion.

value-filter-\d+\[\]=.+?(?=&value-filter-|$)

DEMO

Upvotes: 1

Related Questions