1

I have the following regex: start([\s\S]*?)end.


The regex should only match between start and end.

start text text text end

And discard matches containing forbidden between start and end.

start text text text forbidden end

I have tried adding a negative lookahead but i can't get it to work.

Daniël Visser
  • 581
  • 3
  • 13

1 Answers1

0

With RegX:

var str='start text text text forbidden end';
var output = str.replace(/ *\b\S*?forbidden\S*\b/g, '');
console.log(output);

Without regx:

var str = "start text text text forbidden end".replace('forbidden','');
console.log(str);   
Dinesh Ghule
  • 3,423
  • 4
  • 19
  • 39