How can I strip all punctuation from a string in JavaScript using regex? -
if have string type of non-alphanumeric character in it:
"this., -/ #! $ % ^ & * example ;: {} of = -_ string `~)() punctuation" how no-punctuation version of in javascript:
"this example of string punctuation"
if want remove specific punctuation string, best explicitly remove want like
replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"") doing above still doesn't return string have specified it. if want remove spaces left on removing crazy punctuation, going want like
replace(/\s{2,}/g," "); my full example:
var s = "this., -/ #! $ % ^ & * example ;: {} of = -_ string `~)() punctuation"; var punctuationless = s.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,""); var finalstring = punctuationless.replace(/\s{2,}/g," "); results of running code in firebug console:

Comments
Post a Comment