【问题标题】:How can I do this with a regex pattern?如何使用正则表达式模式做到这一点?
【发布时间】:2013-02-22 12:16:11
【问题描述】:

我正在为 6502 汇编语言编写自定义 TextMate / Sublime Text 2 包。

无论如何,我希望能够识别常量、变量等。

我有这个HEX 号码:

<dict>
    <key>match</key>
    <string>#?\#[0-9a-fA-F]+</string>
    <key>name</key>
    <string>constant.numeric.decimal</string>
</dict>

但它实际上不适用于以下情况:

#14              // works
#$2F             // works
#coolVariable    // doesn't work.  The "#c" is caught and colored but the rest is not.
                 //                In this case, I DON'T want any of it to be colored.

正如代码所说,它不应该为#coolVariable 着色,但它会抓住#c 的一部分。

我想单独为这样的变量着色。区分这两种模式的正则表达式是什么?

这样:

#c0      //  Caught by one pattern  (values in decimal or hexadecimal or binary)
#%10101  //  Caught by one pattern  (values in decimal or hexadecimal or binary)
#c0BLAH  // Caught by another pattern

谢谢

【问题讨论】:

    标签: regex sublimetext2 textmate


    【解决方案1】:
    \#[0-9a-fA-F]+\b
    

    标记单词必须在使用任何其他字符之前结束。

    【讨论】:

      【解决方案2】:

      使用 \b 作为单词边界

      所以把\b#?\#[0-9a-fA-F]+\b

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-12
        • 2021-08-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-31
        相关资源
        最近更新 更多