T-SQL Decommenter Part II

  • Toby Ovod-Everett

    SSC Enthusiast

    Points: 156

    Comments posted to this topic are about the item T-SQL Decommenter Part II

  • will 58232

    Old Hand

    Points: 350

    Or using powershell and regex

    ([regex]"(?im)--.*?$").replace(([regex]"(?s)\/\*.*?\*\/").replace($sql, ""), "")

  • Toby Ovod-Everett

    SSC Enthusiast

    Points: 156

    will 58232 - Thursday, November 15, 2018 12:03 AM

    Or using powershell and regex

    ([regex]"(?im)--.*?$").replace(([regex]"(?s)\/\*.*?\*\/").replace($sql, ""), "")

    That will work much of the time, but here are a couple of examples that will get mangled:
    ([regex]"(?im)--.*?$").replace(([regex]"(?s)\/\*.*?\*\/").replace("SELECT '-- in string'", ""), "")
    ([regex]"(?im)--.*?$").replace(([regex]"(?s)\/\*.*?\*\/").replace("/*SELECT /*'Nested'*/'Commented'`r`n*/`r`nSELECT 'Uncommented'", ""), "")

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply