1.需要寫幾個正則運算式,提取()[],【】,{},<>中的字串,幾種都需要包含括號和不包含括號的。
uj5u.com熱心網友回復:
只能簡單的幫助下你了,不能匹配括號里面有括號的
public static List<string> RegexMatch(string input, char cStart, char cEnd, bool isHave)
{
MatchCollection matchCollection = Regex.Matches(input, string.Format(@"\{0}(.*?)\{1}", cStart, cEnd));
List<string> listResult = new List<string>();
foreach (var v in matchCollection)
{
string strV = v.ToString();
if (!isHave)
{
strV = strV.Trim(new char[] { cStart, cEnd });
}
listResult.Add(strV);
}
return listResult;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/48031.html
標籤:C#
上一篇:如何計算輸入的數學公式的結果
