如何搜索一行中单词之间出现多个空格 [英] How to search for occurrences of more than one space between words in a line

查看:16
本文介绍了如何搜索一行中单词之间出现多个空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何搜索一行中单词之间出现多个空格的地方

How to search for occurrences of more than one space between words in a line

1. this is a line containing  2 spaces
2. this is a line containing   3 spaces
3. this is a line containing multiple spaces first  second   three   four

以上所有都是此正则表达式的有效匹配项.我应该使用什么正则表达式?

All the above are valid matches for this regex. What regex should I use?

推荐答案

[ ]{2,}

空格(2 个或更多)

您还可以检查这些空格前后的单词是否跟随.(不是其他空格,如制表符或换行符)

You could also check that before and after those spaces words follow. (not other whitespace like tabs or new lines)

w[ ]{2,}w

相同,但您也可以仅选择(捕获)用于替换等任务的空间

the same, but you can also pick (capture) only the spaces for tasks like replacement

w([ ]{2,})w

或者看到空格前后有什么,不只是单词字符(空格除外)

or see that before and after spaces there is anything, not only word characters (except whitespace)

[^s]([ ]{2,})[^s]

这篇关于如何搜索一行中单词之间出现多个空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆