Is is the cost of of gasoline going up up?
使用表达式:
\b([a-z]+) \1\b
匹配结果:
of of
up up
把表达式修改为\b([a-z]+)\b\1\b 就匹配不出来了, \b不是匹配一个字符边界吗? 原以为能够匹配一个空格的.
\b匹配的是一个边界位置,而不是一个边界字符。
The match must occur on a boundary between a \w (alphanumeric) and a \W (nonalphanumeric) character.
改为下面的正而表达式(加一个空格)就可以了:
Regex.Matches(text, @"\b([a-z]+)\b (\1)\b");