如果我有字符串hello world
,我該如何修改正則表達式world|wo|w
,以便它匹配所有「world」,「wo」和「w」,而不僅僅是匹配「world」的第一個匹配項。如何防止正則表達式在第一次匹配時停止?
如果這是不可能的,是否有一個很好的解決方法?我使用C#如果它有所作爲:
Regex testRegex = new Regex("world|wo|w");
MatchCollection theMatches = testRegex.Matches("hello world");
foreach (Match thisMatch in theMatches)
{
...
}
你究竟是什麼意思? – SLaks 2010-05-05 13:35:48