我想在句子fish egg chicken beef
中捕捉群组How much is fish egg chicken beef ?
。我试过
how much is ((?>\w+))* \\?
但它只返回fish
作为第二组。我在这里做错了什么?
答案 0 :(得分:1)
也许正则表达式应该是:
How much is (.*)\?
或者如果你想匹配每个捕获中的所有单词,但只有一个单词:
How much is (?:(\w+)\s*)+\?
Regex regexWords = new Regex(@"How much is (?:(\w+)\s*)+\?");
foreach(Capture word in regexWords.Match(input).Groups[1].Captures)
{
// word.Value contains one word.
}
祝你好运。