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

Viewed 238173

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?

5 Answers

This regex selects all spaces, you can use this and replace it with a single space

\s+

example in python

result = re.sub('\s+',' ', data))
Related