Skip to content Skip to sidebar Skip to footer

Javascript: Replace Comma With ### - Only With In Double Quotes

In the below string, 'This 'is, 'just, for', Test', ignore it. My name is 'FirstName, LastName'.' I want to replace all Commas(,) only inside the double quotes('') with ###. For n

Solution 1:

You can do this using a callback ...

var r = s.replace(/"[^"]+"/g, function(v) { 
      return v.replace(/,/g, '###');
});

Post a Comment for "Javascript: Replace Comma With ### - Only With In Double Quotes"