Posts Tagged ‘regex to remove white spaces’

Replace white spaces – blank spaces in string using Javascript

September 27, 2010 Leave a comment

Regex make our life simpler, and when used properly can create miracles. One such example  Regex is given below which replaces white spaces/blank spaces in string using javascript :

function ReplaceWhiteSpaces()
 var text = "Example to Replace white spaces in strings";
 text = text.replace(/\s/g, "-");

Output : Example-to-Replace-white-spaces-in-strings

Regex Used : /\s/g