/// <summary>
/// return the first match string. use regularExpression. eg. getMatchStr("abc1233dfdfa456","\d+")
/// </summary>
/// <param name="str">string</param>
/// <param name="regular">reg string</param>
/// <returns></returns>
public string getMatchStr(string str,string regular)
{
MatchCollection matchCol = Regex.Matches(str, regular);
if (matchCol.Count > 0)
{
return Convert.ToString(matchCol[0]);//这个例子是取第一个匹配的字符串
}
else
return "";
}
C#利用正则表达式获取特定格式的字串符
最新推荐文章于 2022-12-18 20:45:52 发布