regex - Sublime Text 3语法定义: how to capture a multiline C-style block comment?

标签 regex sublimetext sublimetext3

所以目标 block 是这样的:

/* some comments
   more
   end  */

/**/ 之间的任何内容都被视为注释。我当前的规则仅捕获单行注释:

match: \/\*(\w|\s|\W|\n|\r\n)*\*\/

我知道 Sublime Text 使用 Oniguruma但我不知道如何匹配多行。

最佳答案

我在 ST3 上遇到了同样的问题,但使用的是 .sublime-syntax 文件。不同之处在于,在我的语言中, block 注释由 !**! 界定。内联注释以 ! 开头。

这是我使用的解决方案:

contexts:
  # The prototype context is prepended to all contexts but those setting
  # meta_include_prototype: false.
  prototype:
    - include: comments
  comments:
    # Block comments begin with !* and ends with *!
    - match: '!\*'
      scope: punctuation.definition.comment.c
      push: 
        - meta_scope: comment.block.c
        - match: '\*!'
          pop: true
    # Inline comments begin with a '!' and finish at the end of the line.
    - match: '![^\*]'
      scope: punctuation.definition.comment.c
      push:
        # This is an anonymous context push for brevity.
        - meta_scope: comment.line.double-slash.c
        - match: $\n?
          pop: true

关于regex - Sublime Text 3语法定义: how to capture a multiline C-style block comment?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29316457/

相关文章:

sql - Oracle REGEXP_LIKE - 搜索字符串后面没有特定字符

sublimetext - Sublime Text : Switching files in different folders

sublimetext2 - Sublime Text 2 - 在侧边栏中显示文件导航

sublimetext3 - 扩展时如何让 emmet 识别类名中的空格?

java - 在 Sublime Text 3 中构建文件以调用 JUnit5 测试

java - Java 是否有一种有效的方法在 StringBuilder 上执行多个正则表达式 ReplaceAll 操作?

java - 在 JAVA 中验证 CSV 的正则表达式

regex - 基于正则表达式替换数据框列

sublimetext2 - SublimeText 输出显示完成时间

macos - 在 macOS 中从终端打开 Sublime Text