locked
Syntax for regular expression search and replace.

    Question

  • I would like to search and change instance like:

    (string.Compare(testingConnections[i].Configuration, "CommerceServerCatalogConnectionString", StringComparison.OrdinalIgnoreCase) == 0)

    to

    testingConnections[i].ConfigurationEquals("CommerceServerCatalogConnectionString", StringComparison.OrdinalIgnoreCase)

    So this involves regular expressions and it seems that VS's idea of regular expressions differ from the regular expressions used the System.Text.RegularExpression. I need to understand how VS matches a pattern, saves it in a variable and uses it in the replace expression. Like

    With "normal" regular expressions I would search for the pattern like:

    ^\(string\.Compare\(\s*(?<Variable>[^,]+),\s*(?<String>[^,]+),\s*(?<Comparison>[^)]+)\)\s*==\s*0\)

    And replace with

    ${Variable}.Equals(${String}, ${Comparison})

    But I don't understand how this translates to the regular expressions that VS uses. Any ideas?

    Thank you.


    Kevin Burton

    Thursday, August 09, 2012 2:48 PM

All replies