简体   繁体   English

C#-正则表达式无法按预期工作

[英]C# - Regular Expression not working as expected

I have written the following Regular Expression. 我写了以下正则表达式。

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString =@"(\<\![a-b]+\!\>)+") ]

It is to match the string 是为了匹配字符串

<!abc!>

The whole string is required. 整个字符串是必需的。

But this particular expression matches up even with < only. 但是此特定表达式甚至仅与<匹配。 and <! <! too. 太。

Can someone pls correct it if I have done it wrong ? 如果我做错了,有人可以纠正吗?

You are escaping things that you should not, and you did not include c in your range. 您正在逃避不应该使用的东西,并且没有在范围内包括c Here is a correct RegEx: 这是正确的RegEx:

<![a-c]+!>

Tip: Check out http://regexr.com/ It is a great (free) online tool for testing, and learning about, RegEx's. 提示:查阅http://regexr.com/这是一个很棒的(免费)在线工具,用于测试和了解RegEx。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM