mercredi 22 mars 2017

How do I make a regex match a query string?

I'm working on a simple router, and I need to be able to identify if there's a query-like structure at the end of a URL address. What I came up with:

(\?([^&=]+)=([^&=]+)&?)+$

simply does not work! It works on a first iteration (i.e. xxx?foo=bar), but definitely not on two (i.e. xxx?foo=bar&greeting=hello won't work).

What am I doing wrong? And also: Is there a better solution to accomplish this?




Aucun commentaire:

Enregistrer un commentaire