Pure.Krome
Pure.Krome

Reputation: 86987

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 failing to match it.

Can someone help, please?

(i'm guessing i'm screwing up becuase of the \ and the ? in the input expression).

Upvotes: 0

Views: 220

Answers (3)

Ming-Tang
Ming-Tang

Reputation: 17651

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(\?.*)?$

Upvotes: 2

polygenelubricants
polygenelubricants

Reputation: 383886

Maybe something like this is more appropriate:

^/default\.aspx(\?.*)?$

This will match default.aspx, with an optional ?whatever-else-that-comes-after.

Upvotes: 1

pzr
pzr

Reputation: 1256

The $ at the end of ^/default.aspx$ means 'match the end of the string', but the string you're searching ends with '?'.

Upvotes: 1

Related Questions