Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

regex

eclipse

Can someone provide me with a regular expression that will find this string : <% but will exclude this string : <%@ Thanks.


2 Answers

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

<%(?!@)

It will also work in non-.NET applications, but some regular expression implementations don't support (?!)

like image 119
Philippe Leybaert Avatar answered Sep 10 '25 05:09

Philippe Leybaert


The exact correct answer varies between different regex syntaxes, but something like this should work:

<%[^@]

or perhaps this, if your regex syntax allows:

<%([^@]|$)

The latter will also match an occurrence of <% at the end of the string (or line), whereas the first regex probably won't.

Finally, as other posters suggest, this might work too if your regex language has "zero-width negative look-ahead assertions" (like Perl and C#):

<%(?!@)
like image 36
Ville Laurikari Avatar answered Sep 10 '25 04:09

Ville Laurikari