I tried this:
Code: Select all
let str ='This is my text';
str = str.replace(/\s/, '-');
console.log(str); // This-is my text
What is the regex to make it replace all matches in string?
Code: Select all
let str ='This is my text';
str = str.replace(/\s/, '-');
console.log(str); // This-is my text
Code: Select all
let str ='This is my text';
str = str.replace(/\s/g, '-');
console.log(str); // This-is-my-text