Reputation: 3596
In javascript I am trying to remove 3 lines after matching pattern (including line with matching pattern)
#Guest
line 1
line 2
line 3
I know how to do it sed , look here. Don't how to translate to javascript
??? data.replace(/.*#Guest.*+5d/g, '');
Upvotes: 1
Views: 169
Reputation: 67968
You can use something like this.
^([\s\S]*?)\n#Guest.*(?:\n.*){3}
And replace by $1
.See demo.
https://regex101.com/r/rO0yD8/10
var re = /^([\s\S]*?)\n#Guest.*(?:\n.*){3}/g;
var str = 'sdfdsf\nsdfsdf\nsdf\nsdf\n#Guest\nline 1\nline 2\nline 3\ndsfsdf\nsd\nf\nsd\nf\n';
var subst = '$1';
var result = str.replace(re, subst);
Upvotes: 1