regex

regex to find a string, excluding comments


I need a regex to search for the string SQLHELPER that ignores commented code (single line comment or multi line comments). I am searching in visual studio.


Solution

  • You may use

    (?<!^[\p{Zs}\t]*//.*)(?<!/\*(?:(?!\*/)[\s\S\r])*?)\bSQLHELPER\b
    

    See the regex demo.

    Details

    enter image description here