Skip to content

Instantly share code, notes, and snippets.

@RinatValiullov
Last active November 21, 2017 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RinatValiullov/57e1c5f7e2b5369626ee8212bacdff38 to your computer and use it in GitHub Desktop.
Save RinatValiullov/57e1c5f7e2b5369626ee8212bacdff38 to your computer and use it in GitHub Desktop.
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