Consider I have a URL need to match, which may or may not include the query parameter enforceLogin
.
To find whether enforceLogin is exist in URL, I wrote regexp like this:
/(enforceLogin=(\d+))?/.exec('something?enforceLogin=1')
I hope it could be matched but it returns
["", undefined, undefined]
But after I add $
to the end of the regexp or remove the ?
at the end of regexp, it matched correctly.
Here comes the question, why the first regexp could not work? The string actually has enforceLogin=1
in it.
And if the question mark in the tail of regexp makes it lazier to match the content, why add $
to the end makes it work again?