简体   繁体   English

在正则表达式中使用':'(0x3A)字符?

[英]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.

相关问题 “&#39;:&#39;字符,十六进制值0x3A,不能包含在名称中” - “The ':' character, hexadecimal value 0x3A, cannot be included in a name” XmlWriter &#39;:&#39; 字符,十六进制值 0x3A,不能包含在名称中 - XmlWriter The ':' character, hexadecimal value 0x3A, cannot be included in a name &#39;:&#39; 字符,十六进制值 0x3A,不能包含在名称中 - The ':' character, hexadecimal value 0x3A, cannot be included in a name Xml到列表代码出错。 &#39;:&#39;字符,十六进制值0x3A,不能包含在名称中 - Error in Xml to List code. The ':' character, hexadecimal value 0x3A, cannot be included in a name RestSharp 请求错误? , XML , &#39;:&#39; 字符,十六进制值 0x3A,不能包含在名称中 - Error in RestSharp Request? , XML , The ':' character, hexadecimal value 0x3A, cannot be included in a name System.Xml.XmlException: &#39;:&#39; 字符,十六进制值 0x3A,不能包含在名称中 - System.Xml.XmlException: The ':' character, hexadecimal value 0x3A, cannot be included in a name System.Xml.XmlException:“‘:’字符,十六进制值 0x3A,不能包含在名称中。” - System.Xml.XmlException: „The ':' character, hexadecimal value 0x3A, cannot be included in a name.” 使用Regex提取句子的最后一个字符 - Extracting last character of a sentence using Regex 索引 2 处的路径中的卷分隔符 char ':' (0x3A) 无效 - Invalid volume separator char ':' (0x3A) in path at index 2 C#XML-为什么此代码始终失败并显示0x3A错误? - C# XML - Why does this Code keep failing with 0x3A Error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM