[英]Regex to match words in sentence after a pattern
我想捕捉小組fish egg chicken beef
在句子中How much is fish egg chicken beef ?
。 我嘗試過
how much is ((?>\w+))* \\?
但它僅是第二組返回的fish
。 我在這里做錯了什么?
也許正則表達式應該是:
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.
}
祝您一切順利。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.