简体   繁体   English

C#/ regex,简单问题

[英]C#/regex, simple question

How comes this writes False? 这怎么写错?

Console.Write(Regex.IsMatch("[abcde]{1,16}", "babe")); 

What's wrong with my regex? 我的正则表达式有什么问题? Doesn't that regex roughly translate to: contains between 1 and 16 characters, a through e? 该正则表达式是否大致翻译为:包含1到16个字符,从a到e?

Your arguments are switched. 您的论点已切换。 Ie, use: 即,使用:

Regex.IsMatch("babe", "[abcde]{1,16}")

instead, 代替,

That's going to match any of the characters in "babe" that fall between a and e. 这将匹配“婴儿”中介于a和e之间的任何字符。 So for example, "babez" would match as "babe". 因此,例如,“ babez”将匹配为“ babe”。 I get the sense you want treat it as a string match. 我知道您想将其视为字符串匹配。 Try: 尝试:

[a-e]{1,16}$

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

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