regex to find a string, excluding comments
regex to find a string, excluding comments
You may use
(?<!^[p{Zs}t]*//.*)(?<!/*(?:(?!*/)[sSr])*?)bSQLHELPERb
See the regex demo.
Details
(?<!^[p{Zs}t]*//.*)
– a negative lookbehind that fails the match if, immediately to the left of the current location, the following pattern does not match:^
– start of line[p{Zs}t]*
– any 0+ horizontal whitespaces//
– a//
substring.*
– any 0+ chars other than line break chars
(?<!/*(?:(?!*/)[sSr])*?)
– – a negative lookbehind that fails the match if, immediately to the left of the current location, the following pattern does not match:/*
– a/*
substring(?:(?!*/)[sSr])*?
– (tempered greedy token) any char (matched with[sSr]
), 0 or more repetitions but as few as possible (due to*?
) that does not start a*/
substring (due to the(?!*/)
negative lookahead)
bSQLHELPERb
– a whole wordSQLHelper
(b
are word boundaries).