mardi 5 mai 2015

Capturing key value pairs from a url string with a regex pattern

I'm trying to use regex to parse a string like the below:

/subject=hello±@text=something that may contain\@hello.com or a normal sla/sh±@date=blah/somethingelseI don't want to capture after the first/

into:

subject = hello
text =something that may contain\@hello.com or a normal sla/sh
date = blah

Ideally I'd like to be able to split the string by only the first '/' and then something like '±@' - and only that combination in that order.

I've looked around and at the minute have the below:

([^/±@,= ]+)=([^±@,= ]+)

But this doesn't match only '±@' - it matches either @ or ±. It also doesn't cope with the escaped @. (Instead i get: text= something that may contain\ ).

Is there a better way to do this?

Thanks

Aucun commentaire:

Enregistrer un commentaire