Answers for "replace set of characters in string javascript"

7

replacing characters in string javascript

var myStr = 'this,is,a,test';
var newStr = myStr.replace(/,/g, '-');

console.log( newStr );  // "this-is-a-test"
Posted by: Guest on October-20-2020
6

js replace characters in a string

var str = "Original string!";
var str = str.replace("Original", "New");
Posted by: Guest on September-29-2020
1

replace many chracters js

// You can use regex to do it in only one replace
// Using the or: |
var str = '#this #is__ __#a test###__';
str.replace(/#|_/g,''); // result: "this is a test"
// Or using the character class 
str.replace(/[#_]/g,''); // result: "this is a test"
Posted by: Guest on September-21-2020
0

multiple replace

var str = '[T] and [Z] but not [T] and [Z]';
var result = str.replace('T',' ').replace('Z','');
console.log(result);
Posted by: Guest on May-12-2020

Code answers related to "replace set of characters in string javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language