Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add spaces in string and deleted first blank (with regular expressions)
let addSpaces = (str) => {
str = str.replace(/([A-Z])/g, ' $1');
let removeInitBlank = () => {
return str.replace(/^\s/, '');
}
return removeInitBlank();
};
/* for example */
addSpaces('ILoveJavascript!'); // I Love Javascript!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment