I'm using the following regex to capture a fixed width "description" field that is always 50 characters long:
(?.{50})
My problem is that the descriptions sometimes contain a lot of whitespace, e.g.
"FLUID COMPRESSOR "
Can somebody provide a regex that:
Substitute two or more spaces for one space:
s/ +/ /g
Edit: for any white space (not just spaces) you can use \s if you're using a perl-compatible regex library, and the curly brace syntax for number of occurrences, e.g.
s/\s\s+/ /g
or
s/\s{2,}/ /g
Edit #2: forgot the /g global suffix, thanks JL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With