I want to remove any space that is present between two dots using regex, for example:
我想使用正则表达式删除两个点之间存在的任何空格,例如:
s . . . . e
--> s .... e
s。 。 。 。 e - > s .... e
I tried replacing \.\s+\.
to ..
but this works as following:
我试过替换\。\ s + \。到..但这可以如下工作:
s . . . . e
--> s .. .. e
s。 。 。 。 e - > s .. .. e
As you can see, it finds the first match between the first and second dot, and advances to the next character after the match, and then finds a match between the third and forth dot, and so the match between the second and third dot is ignored.
如您所见,它找到第一个和第二个点之间的第一个匹配,并在匹配后前进到下一个字符,然后在第三个和第四个点之间找到匹配,因此第二个和第三个点之间的匹配是忽略。
How can I write my regular expression to correctly handle this?
如何编写正则表达式来正确处理?
1 个解决方案
#1
2
Use regex look ahead assertion as follows
使用正则表达式查看断言如下
\.\s+(?=\.)
And replace it with single dot(.
) string.
并用单点(。)字符串替换它。
#1
2
Use regex look ahead assertion as follows
使用正则表达式查看断言如下
\.\s+(?=\.)
And replace it with single dot(.
) string.
并用单点(。)字符串替换它。