Can someone give me an example/explanation what this regular expression does:
(?![#$])
This is part of <%(?![#$])(([^%]*)%)*?> which is what ASP.NET uses to parse server-side code blocks. I understand the second part of the expression but not the first.
I checked the documentation and found (?! ...) means a zero-width negative lookahead but I'm not entirely sure I understand what that means. Any input I tried so far that looks like <% ... %> seems to work - I wonder why this first sub-expression is even there.
Edit:
I came up with this expression for picking up ASP.NET expressions: <%.+?%> then I found the one Microsoft made (the above full expression in question). I'm trying to understand why they chose that particular expression when mine seems a lot simpler. (I'm trying to see if my expression ignores certain boundary conditions that the MS one doesn't.)
It's a negative lookahead assertion that matches if the next character is not # or $, but doesn't consume it.
It's very simlar to the negative character class [^#$] except that the negative character class also consumes the character, preventing it from being matched by the rest of the expression.
To see the difference consider matching <%test%>.
<%(?![#$])(([^%]*)%)*?> captures test%. (rubular)<%[^#$](([^%]*)%)*?> captures est% because the t was consumed by the negative character class. (rubular)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With