Hi. Can someone provide me with a regular expression that will find this string : <% but will exclude this string : <%@ Thanks.
How about this one
<%([^@]|$)
It matches the end of the string or [^@], which is a character class containing all characters except @
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 (?!)
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#):
<%(?!@)
Based on your updated request, either of these will work:
<%(?!@|-)
<%(?![@-])