62,046
社区成员
发帖
与我相关
我的任务
分享
string s = "[aaa]bbb";
Regex regex=new Regex("\\[(?<a>\\w+)\\](?<b>\\w+)",RegexOptions.IgnoreCase);
string a = string.Empty;
string b = string.Empty;
Match m = regex.Match(s);
if (m.Success)
{
a = m.Groups["a"].ToString();
b = m.Groups["b"].ToString();
}
string str = "[aaa]bbb";
Regex reg = new Regex(@"\[([^\]]+)\](.*)");
Console.WriteLine(reg.Match(str).Groups[1].Value);
Console.WriteLine(reg.Match(str).Groups[2].Value);
string tempStr = "[aaa]bbb";
string pattern = @"\[([\s\S]*)\]([\s\S]*)";
Regex re = new Regex(pattern);
string str1 = Regex.Replace(tempStr,pattern,"$1");
string str2 = Regex.Replace(tempStr, pattern, "$2");
string str = "[aaa]bbb";
Regex re = new Regex("^\\[(.*)\\](.*)$", RegexOptions.None);
MatchCollection mc = re.Matches(str);
foreach (Match ma in mc)
{
//ma.Groups[1].Value 结果:aaa
//ma.Groups[2].Value; 结果:bbb
}