我该如何用正则表达式来做到这一点?
问题描述:
我正在为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
感谢
答
\#[0-9a-fA-F]+\b
为了纪念这个词必须在任何其他字符结束被使用。
答
使用\ b。对于字boundry
所以就把\b#?\#[0-9a-fA-F]+\b