Regular expression using Sublime

Using my text editor, Sublime 2, I want to search for code that has unauthorized warnings. So I need a regular expression that finds "alert" but not "// alert" or "// alert". I do not know how to invert and then combine the two results. Sublime Text uses Boost syntax for regular expressions. Thanks for any help.

+4
source share
2 answers

You can search for text not preceding // in this way

 (?<!\/\/\s?)alert 

EDIT: If the editor does not support lookbehinds variables, you must specify all the features in different lookbehinds

 (?<!\/\/\s)(?<!\/\/)alert 
+9
source

try the following:

 (?<!//)(?<!// )alert 

Boost syntax is based on Pearl RegExp. Thus, a negative lookbehind (?<!text) must be supported. In this example, I use negative lookbehind twice (with and without space) because the lookbehind text must be a fixed length.

You can learn more about the lookaround function in RegExp:
http://www.regular-expressions.info/lookaround.html

+6
source

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


All Articles