What does this regular expression mean: (?! [# $])

Can someone give me an example / explanation of what this regex does:

(?![#$])

This is the part <%(?![#$])(([^%]*)%)*?>that ASP.NET uses to analyze blocks of code on the server side. I understand the second part of the expression, but not the first.

I checked the documentation and found what the (?! ...)negative back side of zero width means, but I'm not quite sure I understand what that means. Any input I've tried so far that looks like <% ... %>it seems to work - I wonder why this is the first subexpression even there.

Edit: I came up with this expression to select ASP.NET: expressions <%.+?%>, after which I found the one that Microsoft made (the above full expression). I’m trying to understand why they chose this particular expression when it seems a lot easier to me. (I am trying to check if my expression does not ignore some boundary conditions that MS does not.)

+3
source share
1 answer

This is a negative lookback> statement that matches if the next character does not #or $, but does not use it.

This is very similar to the negative character class [^#$], except that the negative character class also consumes the character, preventing it from being matched to the rest of the expression.

, <%test%>.

+4

All Articles