普通EX pression找到非转义字符 [英] Regular expression to find non-escaped characters
本文介绍了普通EX pression找到非转义字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要找到与格式的十六进制字符 _x [0-9A-F] {4} _
,除非它们是由<$ pceded $ P code> _x005F (使用.NET)
I need to find the hex characters with the format _x[0-9A-F]{4}_
except when they're preceded by _x005F
(using .Net)
我试过 [^(_ x005F)_ X [0-9A-F] {4} _
,但它不工作,因为它会匹配 _x005F _
的字符串 AA_x005F_x00FF_BB
(在这种情况下,我不希望它匹配任何东西)。
I tried [^(_x005F)]_x[0-9A-F]{4}_
but it doesn't work because it would match _x005F_
on the string AA_x005F_x00FF_BB
(in this case I don't want it to match anything).
推荐答案
您的问题并不能使它很清楚,但你似乎有两个非常类似的要求:
Your question doesn't make it very clear, but you seem to have two very similar requirements:
- 请不要匹配,如果 previous 的字符
x005F
。 - 请不要匹配,如果电流的字符
x005F
。
- Don't match if the previous characters are
x005F
. - Don't match if the current characters are
x005F
.
试试这个:
"(?<!_x005F)_x(?!005F)[0-9A-F]{4}_"
完整的示例:
Full example:
string s = "AA_x0042_x005F_x00FF_x0043_BB";
foreach (Match match in Regex.Matches(s, "(?<!_x005F)_x(?!005F)[0-9A-F]{4}_"))
{
Console.WriteLine(match.Value);
}
输出:
_x0042_
_x0043_
请参阅它的在线工作: ideone
See it working online: ideone
这篇关于普通EX pression找到非转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文