【发布时间】:2015-05-06 08:45:49
【问题描述】:
我有一个这样的字符串:
[[[a]]][[[b]]][[[c]]]
我想提取这些:
a
b
c
所以我写了以下模式:
@"\[\[\[(.+?)\]\]\]"
使用以下代码
string input = "[[[a]]][[[b]]][[[c]]]";
Regex regexObj = new Regex(@"\[\[\[(.+?)\]\]\]");
foreach (Match er in regexObj.Matches(input))
{
MessageBox.Show(er.Value);
}
结果是:
[[[a]]]
[[[b]]]
[[[c]]]
这是怎么回事?你能帮帮我吗?
【问题讨论】:
-
字符串输入 = "[[[a]]][[[b]]][[[c]]]";正则表达式 regexObj = new Regex(@"[[[(.+?)]]]"); foreach (在 regexObj.Matches(input) 中匹配 er) { MessageBox.Show(er.Value); }
-
你得到了匹配,但你不是在寻找组的捕获:er.Groups[0].Captures[0].Value.
-
@Boggin
Groups[0]是整场比赛。 -
我吃早餐的时候这么简单的问题?不公平。 :)