Link to home
Start Free TrialLog in
Avatar of tmajor99
tmajor99

asked on

Regular Expression to remove all spaces

I need a regular expression that will remove all spaces from a string including leading and training spaces.  

Data:                         Expected Result
 L P M                       LPM
    LPM                      LPM
LPM                          LPM
L PM                         LPM    
L   P M                      LPM   (double space example)
1 0 0 0                      1000
Avatar of Bill Prew
Bill Prew

I don't see why you would use RegEx for this.  Almost all languages have a "replace" function, just use that, like below.  Much faster and simpler...

s = Replace(s, " ", "")


»bp
A regular expression replacement would just use a single space as the pattern, and an empty string as the replacement. If you also wanted to replace line feed, newline and tab characters, the pattern would be \s
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial