Match m = Regex.Match("", "(?i)(?<=" + fieldname + "=)[^;]+(?=;|$)");
好像你们的方法只是获取了 第一组匹配的 子串,,可能我方法错误,求指教 string pattern = "(?<==).*?(?=;|$)"; //pattern = "(?<==)[^;$]+"; Regex rg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline); Match m = rg.Match(str); string str1 = ""; foreach (Group col in m.Groups) { str1 += col.Value + " "; }
MatchCollection collection = rg.Matches(str); foreach(Match m in collection ) console.writeline(m.Value);
Regex regs = new Regex(@"(?<==).*?(?=;|$)"); string s = "server=xx;uid=xx;pwd=;database=xx"; string ss=""; MatchCollection mc = regs.Matches(s); foreach (Match m in mc) { ss += m.Groups[0].Value.ToString(); }
//pattern = "(?<==)[^;$]+";
Regex rg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline); Match m = rg.Match(str);
string str1 = ""; foreach (Group col in m.Groups)
{
str1 += col.Value + " ";
}
foreach(Match m in collection )
console.writeline(m.Value);
string s = "server=xx;uid=xx;pwd=;database=xx";
string ss="";
MatchCollection mc = regs.Matches(s);
foreach (Match m in mc)
{
ss += m.Groups[0].Value.ToString();
}