SteffenM
SteffenM

Reputation: 81

Regular Expression: convert a list of name and value pairs to query string

I am working on an URL rewrite with Lucee/Tomcat and the Tuckey plugin. To simplify the problem: I need a regular expression that converts a list delimited by colons, to a regular url query string format.

For example, convert this

one1:aaa:two2:bbb:three3:ccc 

into this:

one1=aaa&two2=bbb&three3=ccc 

The list length may vary. The parameter names and their values are alpha-numeric.

Ideally, I would like to replace every odd numbered occurrence of the delimiter : with a =, and replace even numbered occurrences with &.

Upvotes: 3

Views: 325

Answers (1)

Josh Beauregard
Josh Beauregard

Reputation: 2749

I would look at something like this.

(\w+):(\w+):? and replace with $1=$2& and then just strip the final ? of in a second command.

See my work https://regex101.com/r/7nh1Mb/1

Upvotes: 4

Related Questions