[英]Use the ':' (0x3A) character in a Regex sentence?
No, this is not a replicate of The ':' character, hexadecimal value 0x3A, cannot be included in a name 不,这不是':'字符的副本,十六进制值0x3A,不能包含在名称中
I have a Regex for my syntax highlighter for my scripting language: 我的脚本语言语法荧光笔有一个正则表达式:
`@"\bClass+(?<range>\w+?)\b"`
which basically marks Class Name 基本上标记了类名
(with the engine I got online) (使用我上线的引擎)
I'm no master in Regex but for some reason the :
character that uses my language to create labels - doesn't work. 我不是Regex的管理员,但由于某种原因,使用我的语言创建标签的:
字符不起作用。
I tried 我试过了
@"\b:+(?<range>\w+?)\b"`, `@"\b\:+(?<range>\w+?)\b"`<RB> `@"\b(\x3A)+(?<range>\w+?)\b"
And it refuses to work! 而且它拒绝工作!
Any ideas? 有任何想法吗?
I suspect the issue in your case is not the :
itself, but the \\b
before it. 我怀疑您遇到的问题不是:
本身,而是它前面的\\b
。 \\b
marks the boundary between a word character and nonword character, but while Class
is comprised of word characters, :
is a nonword character. \\b
标记单词字符和非单词字符之间的边界,但是虽然Class
由单词字符组成,但:
是一个非单词字符。 So \\b
is behaving differently for :
than it would for Class
, so: 所以, \\b
是表现不同的:
比它的Class
,所以:
`\bClass` matches " Class Name"
`\b:` does not match " : Name"
If you use your original expression but replace the first \\b
with (?<!\\w)
, it may identify the :
properly. 如果使用原始表达式,但用(?<!\\w)
替换第一个\\b
,则它可能会正确标识:
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.