Skip to main content
edited title
Link
HarshWombat
  • 169
  • 2
  • 2
  • 9

How do I replace all spaces, commas and periods in a variable using javascript

edited body
Source Link
HarshWombat
  • 169
  • 2
  • 2
  • 9

I have tried var res = str.replace(/ |,|.|/g, ""); and var res = str.replace(/ |,|.|/gi, "");. What am I missing here?

var str = "Text with comma, space, and, period."; var res = str.replace(/ |,|.|/g, ""); document.write(res);

I have tried var res = str.replace(/ |,|.|/g, ""); and var res = str.replace(/ |,|.|/gi, "");. What am I missing here?

var str = "Text with comma, space and, period."; var res = str.replace(/ |,|.|/g, ""); document.write(res);

I have tried var res = str.replace(/ |,|.|/g, ""); and var res = str.replace(/ |,|.|/gi, "");. What am I missing here?

var str = "Text with comma, space, and period."; var res = str.replace(/ |,|.|/g, ""); document.write(res);

Oxford comma
Source Link
HarshWombat
  • 169
  • 2
  • 2
  • 9

I have tried var res = str.replace(/ |,|.|/g, ""); and var res = str.replace(/ |,|.|/gi, "");. What am I missing here?

var str = "Text with comma, space and, period."; var res = str.replace(/ |,|.|/g, ""); document.write(res);

I have tried var res = str.replace(/ |,|.|/g, ""); and var res = str.replace(/ |,|.|/gi, "");. What am I missing here?

var str = "Text with comma, space and period."; var res = str.replace(/ |,|.|/g, ""); document.write(res);

I have tried var res = str.replace(/ |,|.|/g, ""); and var res = str.replace(/ |,|.|/gi, "");. What am I missing here?

var str = "Text with comma, space and, period."; var res = str.replace(/ |,|.|/g, ""); document.write(res);

Source Link
HarshWombat
  • 169
  • 2
  • 2
  • 9
Loading