What is wrong with this really really simple RegEx expression?
this one is really easy.
I'm trying to create a Regular Expression that will result in a Successful Match when against the following text
/default.aspx?
So i tried the following...
^/default.aspx$
and it's f开发者_如何转开发ailing to match it.
Can someone help, please?
(i'm guessing i'm screwing up becuase of the \
and the ?
in the input expression).
The problem is in the .
(dot), which is a wildcard,
You must escape it like \.
.
Also, Because there is a ?
at the end of URL and $
(end-of-input) is in the regexp, therefore, it does not match.
The correct regexp should be ^/default\.aspx(\?.*)?$
The $ at the end of ^/default.aspx$ means 'match the end of the string', but the string you're searching ends with '?'.
Maybe something like this is more appropriate:
^/default\.aspx(\?.*)?$
This will match default.aspx
, with an optional ?whatever-else-that-comes-after
.
精彩评论