簡體   English   中英

正則表達式,用於匹配給定字符串中長度為2的數字

[英]regular expression to match numbers of length 2 from given string

如何創建一個正則表達式,它將匹配給定字符串中長度為2的數字。

輸入示例:

givenpercentage@60or•70and 8090

所需的輸出:

60 70 80 90

嘗試這個:

string x = "givenpercentage@60or•70and 8090";
Regex r = new Regex(@"\d{2}");
foreach(Match m in r.Matches(x))
{
     string temp = m.Value;
     //Do something
} 

\\d >僅數字

{2} ->僅2個數字

輸出將是:

60 70 80 90 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM