[thelist] Regex Riddle

Jason Handby jason.handby at corestar.co.uk
Sat Aug 28 18:39:06 CDT 2010

Hi Frank,

> Essentially, what I want to do is to replace ampersands ( & and &)
> and
> equal signs (=) with a forward slash (/). So essentially, I'm going
> from
> index.cfm?foo=bar&poo=bear to index.cfm?foo/bar/poo/bear
> My regexes mostly match the overall string, but capture incorrectly to
> one
> degree or another, the backreferences are all wrong.
> Below are my three most (dubiously) sucessful regexes, the replace
> test I
> use just to check out how it all parses, and some sample data to be
> matched.
> Number 3 is probably the closes, but I can't seem to figure out how to
> get
> (\w+)=(\w+)([&|&]*) to be greedy until the end of the query
> How would you approach this problem?

Try this.

Regular expression      ([^?&=]*)(?:&[^a]|=|&)

Replacement expression  \1/


More information about the thelist mailing list