I'm trying to create a very simple regex that accepts strings:
my code is:
Regex.IsMatch("AA00000000000", $"^[A-Za-z]{2}[0-9]*$")
but it returns False. Where am I wrong? I've already tested the same regex with the same input on regexstorm.net and it works.
Working for me with below code:
string pattern = @"^[A-Za-z]{2}[0-9]*$";
string str = "AA00000000000";
bool val = Regex.IsMatch(str, pattern);
你在正则表达式前面放了一个“$”,因为“{2}”部分将被解释为“2”,所以被评估的正则表达式看起来像这样:“^[A-Za-z ]2[0-9]*$”。
Regex.IsMatch method return boolean value. Please, try with this way. You can also try with using "$"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.