Match.Groups 属性
Match.Groups 属性定义
public virtual GroupCollection Groups { get; }
Group 类型 GroupCollection属性(索引):Item[String] 允许通过字符串索引访问集合成员。
Group类型定义:
[SerializableAttribute]
public class Group : Capture
Capture 类:表示单个成功的子表达式捕获的结果。
string result = "{\"access_token\":\"FQSRXOwxRELZLN9ZfRXm2tWiVajEuk7pesRI74vCrH8sfqL4XqX2_aT_HZOLTmgD5_4s884sYVpBqtZDFNAc1EQTJ84aZTj5GDP7wVg0BgoYoWffgmTQMNik1HtC7mVjzbuYdMzhJxFx - sL6SbodMfd_Yzq_iwuy6rW4Myg0zLsQFKSoyCCHCsIOEzcFI9geKXqvVe8uNQomEhewRQt40Q\",\"expires_in\":7200}";
string regex = "\"access_token\":\"(?<token>.*?)\"";
string token = CRegex.GetText(result, regex, "toke");
public static string GetText(string sInput, string sRegex, string sGroupName)
{
Regex re = new Regex(sRegex, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline);
Match mc = re.Match(sInput);
string result = "";
if (mc.Success)
{
if (sGroupName != "")
{
result = mc.Groups[sGroupName].Value;
}
else
{
result = mc.Value;
}
}
return result;
}