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:
- Trims all whitespace off the end
- Collapses any whitespace in between words to a single space
Substitute two or more spaces for one space:
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.
or
Edit #2: forgot the /g global suffix, thanks JL