Created
April 4, 2022 15:58
-
-
Save upning/95cad111cefd83208f96fd392239e2d9 to your computer and use it in GitHub Desktop.
[Remove space from a string] Using REGEX in JS #regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// https://stackoverflow.com/questions/5963182/how-to-remove-spaces-from-a-string-using-javascript | |
str = str.replace(/\s+/g, ''); | |
// \s is the regex for "whitespace", and g is the "global" flag, meaning match ALL \s (whitespaces). | |
// A great explanation for + can be found https://stackoverflow.com/questions/5964373/is-there-a-difference-between-s-g-and-s-g | |
// Alternative | |
var a = b = " /var/www/site/Brand new document.docx "; | |
console.log( a.split(' ').join('') ); | |
console.log( b.replace( /\s/g, '') ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment