Regular expression to remove comments from SQL statement

后端 未结 8 1711
时光说笑
时光说笑 2020-12-15 12:51

I\'m trying to come up with a regular expression to remove comments from an SQL statement.

This regex almost works:

(/\\*([^*]|[\\r\\n]|(\\*+([^*/]|         


        
相关标签:
8条回答
  • 2020-12-15 13:18

    Please see my answer here. It works both for line comments and for block comments, even nested block comments. I guess you need to use regex with balancing groups, which AFAIK is not available in VBScript.

    0 讨论(0)
  • 2020-12-15 13:20

    For Node.js, see pg-minify library. It works with PostgreSQL, MS-SQL and MySQL scripts.

    It can handle all types of comments, plus compress the resulting SQL to its bare minimum, to optimize what needs to be sent to the server.

    0 讨论(0)
提交回复
热议问题