Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
714 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
[ ]{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]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...