Arno
Arno

Reputation: 15

Exclude Specific Line By Regex

Wanna exclude the specific line "//2" from choose item. <%-- //1 --%>

<%-- //1
//1 --%>

<%-- //1
//1
//1 --%>

//2

<%-- //1 --%>

<%-- //1 //1 --%>

//3

By JavaScript, Here is the regex: (?<=<%-{2}[\w\W]*?)\/\/(?=[\w\W]*?-{2}%>)

I found many ways but didn't work out. Could somebody have a good idea to fix it?

Upvotes: 0

Views: 32

Answers (1)

The fourth bird
The fourth bird

Reputation: 163287

You could match the opening <%-- and then match until you encounter // without matching either <%-- or --%>

Then do the same after matching // again.

In Javascript, instead of using [\w\W] you can also use [^].

(?<=<%--(?:(?!<%--|--%>)[^])*)\/\/(?=(?:(?!<%--|--%>)[^])*--%>)

Regex demo

Upvotes: 1

Related Questions