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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With