考慮下面的代碼:字邊界問題的正則表達式(重疊)
var myList = new List<string> { "red shirt", "blue", "green", "red" };
Regex r = new Regex("\\b(" + string.Join("|", myList.ToArray()) + ")\\b");
MatchCollection m = r.Matches("Alfred has a red shirt and blue tie");
我想要的m
結果包括"red shirt", "blue", "red"
,因爲所有這些都是字符串,但我只得到"red shirt", "blue"
。我能做些什麼來包括重疊?