簡體   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