Reputation: 33
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
value-filter-29[]=Test+1,Test+2,Test+2&+3
value-filter-43[]=Last+30+Days
value-filter-11[]=Testing+number
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
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
Reputation: 174826
You need to use a positive lookahead assertion.
value-filter-\d+\[\]=.+?(?=&value-filter-|$)
Upvotes: 1