0

我想fish egg chicken beef在句子中捕获组How much is fish egg chicken beef ?。我试过了

how much is ((?>\w+))* \\?

但它只fish作为第二组返回。我在这里做错了什么?

4

1 回答 1

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.
}

祝你的任务好运。

于 2013-08-24T19:51:10.767 回答