I'm checking for a very specific pattern in URLs so that a set of code is only executed on the correct type of page. Currently, I've got something like:
/^http:\/\/www\.example\.com\/(?:example\/[^\/]+\/?)?$/;
So, it'll return true
for example.com
and example.com/example/anythinghere/
. However, sometimes this website will append arguments such as ?postCount=25
or something to the end of the URL, so you get:
example.com/example/anythinghere/?postCount=25
Because of this, if I throw the current expression into a conditional, it will return false should there be URL arguments. How would I best go about changing the regex expression to allow for an optional URL argument wildcard, so that, if there's a question mark followed by any additional information, it will always return true, and, if it's omitted, it will still return true?
It would need to return true for:
http://www.example.com/?argumentshere
and
http://www.example.com/example/anythinghere/?argumentshere
As well as those same URLs without the extra arguments.