正则表达式,用于查找C样式块注释

lin*_*ize 18 regex

如何使用正则表达式找到这种模式?

C风格块评论

/* xxxxxxxxxxxx */

Cam*_*ire 28

尝试使用

\/\*(\*(?!\/)|[^*])*\*\/
Run Code Online (Sandbox Code Playgroud)

捕获单行和多行块注释.它搜索/*后跟任意数量的任何一个:

  • 一个*没有跟着的/
  • 任何炭除外 *

然后*/再次关闭.

  • 使用```/\*.*?\*/```会不会更简单. (4认同)