Search for commented-out code using regex in visual studio


  • So, I got this regex, which is supposed to search for lines containing code which has been commented out.

    The idea is to look for the "//" and then an ending semicolon.

    Except it does not work. It gives me hits on lines with "//" but also without any semicolon.

    • ^ -> Start of line
    • [\s]* -> Any white space
    • \/\/ -> the two //
    • (\w|\d|\s)* -> Any number of charactes and numbers and whitespace in any mix.
    • ; -> The required semicolon
    • .$ -> End of line (Visual Studio style)

    I get to many results - including some that does not have a semicolor as the last character on the line

    If I replace the ";" near the end with something else, it seems to work fine. It also works fine on regex101 with the ";".

    ? Why does not not just find lines with // and ;?

    ? How do I make it do, as I want?

    Tuesday, July 10, 2018 10:23 AM