I’m creating some reports in Google Analytics.
I am trying to write a RegEx that will match
http://www.website.com/?_string_begins_with_question_mark
But will not match
http://www.website.com/string_doesnt_begin_with_question_mark
Using Reggy (with POSIX Extended), I tried to create an optional group that would match a string beginning with a question mark, followed by any number of characters. I thought
(\?.+)?
would do the trick, but it ignores the question mark requirement, and matches any string.
I tried some variations:
http://www.website.com/(\?(.+))?
http://www.website.com/(\?.+)?
http://www.website.com/(?.+)?
Et cetera.
Any help is appreciated – Sorry if this has already been asked! I’m new to RegEx.
Thank you!
Your regexp
will still match anything that contains
www.website.com/, no matter what comes after the slash. Have you tried appending a$(end-of-input marker)?(Escape the dots for more precision; the
?:is just a way of indicating that the group is of no special meaning and does not have to be remembered — if you omit this, you can access the contents of the group by\1, e.g., in a replace operation.)