捕获评论中被星号包围的内容的正则表达式是什么?

What's the regular expression for capturing something surrounded by asterisks inside a comment?

我正在尝试修改定义如下注释的现有语言定义:

    <dict>
        <key>match</key>
        <string>(#) .*$\n?</string>
        <key>name</key>
        <string>comment.line.number-sign.myLanguage</string>
        <key>captures</key>
        <dict>
            <key>1</key>
            <dict>
                <key>name</key>
                <string>punctuation.definition.comment.myLanguage</string>
            </dict>
        </dict>
    </dict>

这确保以 # 开头的行将被识别为注释并相应地突出显示。我想做的是用星号包围一个注释词,并让它显示为其他东西,例如 keyword。但是简单地附加这个是行不通的:

    <dict>
        <key>match</key>
        <string>\*([^*]+)\*</string>
        <key>captures</key>
        <dict>
            <key>1</key>
            <dict>
                <key>name</key>
                <string>keyword.myLanguage</string>
            </dict>
        </dict>
    </dict>

但是,如果该行不是以 # 开头,它确实有效,所以我假设这两个规则之间存在冲突。所以,我想我可以通过使用正则表达式来解决这个问题,该正则表达式可以识别评论中未被 * 包围的所有内容,例如:

# This is a comment *this is something else* this is still a comment *not* yes

有什么想法吗?

好的,我让它工作了:

<dict>
  <key>begin</key>
  <string>(#) .*</string>
  <key>name</key>
  <string>comment.line.number-sign.myLanguage</string>
  <key>captures</key>
  <dict>
      <key>1</key>
      <dict>
          <key>name</key>
          <string>punctuation.definition.comment.myLanguage</string>
      </dict>
      <key>0</key>
      <dict>
          <key>patterns</key>
          <array>
            <dict>
              <key>name</key>
              <string>keyword.myLanguage</string>
              <key>match</key>
              <string>\*[^*]+\*</string>
            </dict>
          </array>
      </dict>
  </dict>
  <key>end</key>
  <string>$\n?</string>