Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex using Sublime

Using my text editor of choice, Sublime 2, I want to search through code that has uncommented alerts. So I need a regex for that finds "alert" but not "//alert" or "// alert". I don't know how to invert and then combine the two results. Sublime Text uses the Boost syntax for regular expressions. Thank you for any help.

like image 327
Ghoul Fool Avatar asked Dec 07 '22 11:12

Ghoul Fool


2 Answers

You can search for text not preceeded by //, thus

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

EDIT: If the editor doesn't support variable lookbehinds you must specify all the possibilities in different lookbehinds

(?<!\/\/\s)(?<!\/\/)alert
like image 68
Gabber Avatar answered Dec 25 '22 06:12

Gabber


try this:

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

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

you can read more about lookaraound feature in RegExp here:
http://www.regular-expressions.info/lookaround.html

like image 37
bw_üezi Avatar answered Dec 25 '22 06:12

bw_üezi