Regular expression to find <% but exclude <% @?

Can someone provide me with a regex that finds this line: <% but excludes this line: <% @ Thanks.

+3
source share
4 answers

If you are using .NET, the regular expression you are looking for is:

<%([email protected])

It will also work in non-.NET applications, but some regex implementations do not support (?!)

+5
source

The exact correct answer depends on different regex syntaxes, but something like this should work:

<%[^@]

or perhaps this if your regex syntax allows you to:

<%([^@]|$)

<% ( ), , , .

, , , " " (, Perl #):

<%([email protected])
+2

How about this

<%([^@]|$)

It matches the end of a line or [^ @], which is a character class containing all characters except @

+1
source

Depending on your updated request, any of them will work:

<%([email protected]|-)

<%(?![@-])
+1
source

Source: https://habr.com/ru/post/1710142/


All Articles