JavaScript How to remove word with extra delimiter from given string? remove word with regex,remove word with sed,remove word

I have following string.

var str = "abc, abcd, abc, abcf, abc, abc";

I want to remove abc from a given string with , (space). Basically, I want output something like below.

var output = "abcd, abcf";

Note:- If possible give regex solution(with one replace only).

Things I have tried:-

1) 1st approach

var str = "abc, abcd, abc, abcf, abc, abc";
var w = "abc";
var output = str.split(", ").filter(x => !(x === w)).join(", ");
console.log(output);
Answer:1

Using one replace()

var str = "abc, abcd, abc, abcf, abc, abc";

var rep = "abc";

var r = new RegExp("(, "+rep+"(?![a-z]))|("+rep+"(?![a-z]), )","g");
 
str = str.replace(r, "");

console.log(str);
Answer:2

I got an object which looks like this : { "a": "string not empty", "b": { "c": "string not empty", }, "d": { "e": false, "f": 0, "g": true, ...

I got an object which looks like this : { "a": "string not empty", "b": { "c": "string not empty", }, "d": { "e": false, "f": 0, "g": true, ...

I am following a tutorial in order to perform Asynchronous validation in Angular. What I am trying to achieve is my custom validator which is shouldBeUnique should be call after delay of 2 seconds. I ...

I am following a tutorial in order to perform Asynchronous validation in Angular. What I am trying to achieve is my custom validator which is shouldBeUnique should be call after delay of 2 seconds. I ...

  1. angular settimeout function
  2. angularjs settimeout function
  3. angular timeout function
  4. angular timeout function example
  5. angular timeout function with parameters
  6. angularjs timeout function
  7. angularjs timeout function with parameter
  8. angularjs timeout function example
  9. angular 6 settimeout function
  10. angular 4 settimeout function
  11. angular 5 settimeout function
  12. angularjs timeout call function
  13. angular 7 settimeout function
  14. angular settimeout arrow function
  15. settimeout function angular 2
  16. settimeout function angularjs
  17. angularjs settimeout inside function

Why jquery parent child selector is not working here. Here article element has it's children element section, and section contains html select tag. So, with parent child logic, it has to work, isn'...

Why jquery parent child selector is not working here. Here article element has it's children element section, and section contains html select tag. So, with parent child logic, it has to work, isn'...

  1. jquery parent child sibling
  2. jquery parent child selector
  3. jquery parent child selector example
  4. jquery parent child class selector
  5. jquery parent child selector w3schools
  6. jquery parent child
  7. jquery parent child find
  8. jquery parent child class
  9. jquery parent child sibling selectors
  10. jquery parent child click
  11. parentid and child id in jquery
  12. jquery parent child id selector
  13. jquery parent child ul li
  14. jquery parent child table
  15. jquery parent child element
  16. jquery parent child index
  17. jquery parent child count
  18. jquery parent child example
  19. jquery parent child drop down
  20. jquery parent child window communication

I have this body div(ng-class="toggle ? 'nav-open' : 'nav'") .container .logo img(src='images/logo.png') span Motto ul(ng-class="toggle ? 'menu-open' : ...

I have this body div(ng-class="toggle ? 'nav-open' : 'nav'") .container .logo img(src='images/logo.png') span Motto ul(ng-class="toggle ? 'menu-open' : ...