[英].NET Regular expression how to
New to Regex. 正则表达式的新功能。 I want to validate to this format:
我想验证这种格式:
After these strings any character can go 在这些字符串后,任何角色都可以去
Example: 例:
abc{FILE:any text} def {FILE:mno{ENV:xyz}}
FILE:
and ENV:
are an example of specific strings required after a '{' char. FILE:
和ENV:
是'{'char之后所需的特定字符串的示例。 I wrote this regex: 我写了这个正则表达式:
^
(
[^\{\}]+
|
(?<Depth>\{)(FILE:|ENV:)
|
(<-Depth>\})
)*
(?(Depth)(?!))
$
but it doesn't match my desired format. 但它与我想要的格式不符。 What i miss?
我想念的是什么?
Thanks a lot. 非常感谢。
EDIT: Links that do the same, succesfully i hope:-) MSDN , Other site 编辑:链接,做同样的,我希望成功:-) MSDN , 其他网站
You forgot the question mark in the balancing group. 你忘记了平衡组中的问号。
string pattern = @"(?x)
^
(?:
[^{}]+
|
(?<Depth>{) (?:FILE|ENV):
|
(?<-Depth>})
)*
(?(Depth)(?!))
$
";
Should match strings like a {FILE: {ENV: foo } bar } baz
应匹配
a {FILE: {ENV: foo } bar } baz
类a {FILE: {ENV: foo } bar } baz
字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.