Wednesday, August 19, 2009

Regex for parsing HTTP query string

Instead of using lame-ass StringTokenizer looking for an ampersand, here's a regex I found handy:

((\w*)+)(=)[\w\d]*[^(\&)]

The extra parens around the first part token allow you treat the parameter name as a group by iteslf. Could've added it it to the value, as well, I suppose .... but clearly I don't need that now!