Maxim Tkachenko
Maxim Tkachenko

Reputation: 5798

Write regexpression with "not contains"

I have this three strings:

xhtml.AddHtml( g_Lang.Text( Id,L_EXPORT_IS_NOT_SUPPORTED_FOR_THIS_ELEMENT ), false);
xhtml.AddHtml( g_Lang.Text(Id,  L_EXPORT_IS_NOT_SUPPORTED_FOR_THIS_ELEMENT ), false);
sGradeTitle = g_Lang.Text(CustomerID, nTitle, LanguageID);

I want to write regexpression which accepts the third line and doesn't accept the first and the second:

.*g_Lang\.Text\(\s*[A-Za-z]*,\s*[here must be not L_].*

This is what I have tried, could you help me correct it?

Upvotes: 1

Views: 190

Answers (1)

Jerry
Jerry

Reputation: 71548

You were on the right track, you just needed to use (?!.*L_) instead of (?!L_). The .* there will detect L_ anywhere ahead.

.*g_Lang\.Text\(\s*[A-Za-z]*,\s*(?!.*L_).*

You might also want to convert the first greedy .* into lazy to improve the performance a little bit (by reducing the number of backtracking):

.*?g_Lang\.Text\(\s*[A-Za-z]*,\s*(?!.*L_).*

Upvotes: 5

Related Questions