1

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, ''); 
Community
  • 1
  • 1
irom
  • 3,316
  • 14
  • 54
  • 86

1 Answers1

1

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);
vks
  • 67,027
  • 10
  • 91
  • 124
  • Appreciate , when I paste this '''' set wlan vap SSID enable set wlan enable #Guest Wireless (Password must be 8-64 characters) add wlan vap ssid set wlan vap security-type WPA/WPA2''' I got zero matches ? – irom Aug 12 '15 at 20:18
  • 1
    @irom no you just need to press `update regex` and share d link – vks Aug 12 '15 at 20:21
  • I see, when I change from PCRE to JS it doesn't work ? Very close, let me try again – irom Aug 12 '15 at 20:32