繁体   English   中英

正则表达式:仅限AZ字符

[英]Regex: A-Z characters only

嗨,大家好,我有一个字符串...

“ Afds 1.2 45002”

我想使用正则表达式从左开始,返回字符AZ ||。 直到遇到未固定状态为止。

因此,在上面的示例中,我想返回“ Afds”。

另一个例子

“ BCAD 2.11 45099 GHJ”

在这种情况下,我只需要“ BCAD”。

谢谢

您想要的表达式是: /^([A-Za-z]+)/

使用此正则表达式(?i)^[az]+

Match match = Regex.Match(stringInput, @"(?i)^[a-z]+");

(?i) -忽略大小写

^ -字符串的开头

[az] -任何拉丁字母

[az ] -任何拉丁字母或空格

+ -1个或更多previos符号

string sInput = "Afds 1.2 45002";

Match match = Regex.Match(sInput, @"^[A-Za-z]+",
              RegexOptions.None);

// Here we check the Match instance.
if (match.Success)
{
    // Finally, we get the Group value and display it.
    string key = match.Groups[1].Value;
    Console.WriteLine(key);
}

暂无
暂无

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

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