我使用 (.) 来匹配所有字符,但它返回太多匹配项。我如何使它只有1匹配?
private MatchCollection RegexMatchingV2(string data, string regex)
{
MatchCollection col = null;
try
{
col = Regex.Matches(data, regex, RegexOptions.IgnoreCase);
}
catch (Exception ex)
{
Response.Write("RegexMatching ERROR:" + ex.Message);
}
return col;
}
protected void Page_Load(object sender, EventArgs e)
{
MatchCollection col= RegexMatchingV2("return all of this data in 1 match", "(.)");
Response.Write(col.Count);//Too much matches
}