Last active
January 9, 2022 23:17
-
-
Save ciamac-da/d69428102013aff26b59f203a5ef8824 to your computer and use it in GitHub Desktop.
This is how to get rid of white space in javascript string using regular expression
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
// This is how to get rid of white space in javascript string using regular expression | |
let cia = " cia is a lazy programmer " | |
let str = cia.replace(/^\s+|\s+$|\s+(?=\s)/g , "") | |
console.log(str) // Gives: cia is a lazy programmer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment