Is it possible to join these two regex expressions into one?

Posted by Pure.Krome on Stack Overflow See other posts from Stack Overflow or by Pure.Krome
Published on 2010-06-03T06:23:44Z Indexed on 2010/06/03 6:24 UTC
Read the original article Hit count: 285

Filed under:
|
|

Hi folks,

i have the following two regular expressions (in order btw).

1. ^~/buying/(.*)\?(.*)   => foo= group 1  baa= group 2.
2. ^~/buying/(.*)         => foo= group 1  baa= nothing/empty/null/baibai

What's i'm trying to do is, if the url has a questionmark, then split it into two groups. Otherwise, just throw all the stuff into the first group.

the reason why the order is important for me, is that if i switch them round, the '?' regex will never get fired because the #2 expression (above) will catch all.

So .. can this be re-fixed?

NOTE: I have tried using this website** to help me debug/tweak .. but I can't figure it out.

** I have no affiliation with that site.

© Stack Overflow or respective owner

Related posts about regex

Related posts about Simplify