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

后端 未结 5 2024
青春惊慌失措
青春惊慌失措 2020-12-07 13:46

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         


        
5条回答
  •  死守一世寂寞
    2020-12-07 14:07

    [ ]{2,}
    

    SPACE (2 or more)

    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]
    

提交回复
热议问题