Reputation: 24232
Tested with http://regexhero.net/tester/
^(?!Bar$)
Foo
matchesBar
doesn't matchFooBar
matchesBarBaz
matchesFooBarBaz
matchesWhen setting a route constraint, I have to use ^(?!Bar$).*
to get the same results. Why is that?
Upvotes: 1
Views: 575
Reputation: 106483
The first expression actually doesn't 'cover' any part of string. See, both ^
and (?!...)
sub-expressions match at specific positions (anchors) in the tested string (actually they both try to match at the same position - right at the beginning - and fail immediately).
And this - ^(?!Bar$).*
- actually 'covers' all the string. I suppose that's the difference.
Upvotes: 3