Quantcast
Viewing latest article 10
Browse Latest Browse All 16

Regex matching optional section

So I have two possible strings here for example.

/user/name

and

/user/name?redirect=1

I'm trying to figure out the proper regex to match either with a result of:

Array ([0] => /user/name [1] => user [2] => name)

I think the part I'm having an issue with is that the question mark and the GET query after it are optional and will only be there some of the time. I've tried many different things and can't seem to come up with a regex to match the strings whether the ?** is there or not.


Viewing latest article 10
Browse Latest Browse All 16

Trending Articles