I want to select a para of javascript using regex. I need to replace the value with something else, so I am using a Notepad++ editor to do this job. It is a big file which contains this script multiple times. My code is something like this that I want to select :-
<ins class="thisisfirstscript"
style="display:inline-block;width:336px;height:280px"
data-client="ABCD"
data-slot="4397140188"></ins>
<ins class="thisissecondscript"
style="display:inline-block;width:336px;height:280px"
data-client="CDEF"
data-slot="4496122889"></ins>
I want to select each of them separately. You can see data-slot
is different for both cases. So, I want to consider it to select. I am trying with,
<ins class="thisisfirstscript"(.*?)data-slot="4397140188"></ins>
&
<ins class="thisissecondscript"(.*?)data-slot="4496122889"></ins>
But, it is not working. Since, new line character is not including here.
Working answer is :-
/(?:<ins class="thisissecondscript")([\s\S]*)?(?:data-slot="4496122889"><\/ins>)/
Now, second is, suppose, I have same script multiple times. It looks like,
<ins class="thisisfirstscript"
style="display:inline-block;width:336px;height:280px"
data-client="ABCD"
data-slot="4397140188"></ins>
<ins class="thisissecondscript"
style="display:inline-block;width:336px;height:280px"
data-client="CDEF"
data-slot="4496122889"></ins>
<ins class="thisisfirstscript"
style="display:inline-block;width:336px;height:280px"
data-client="ABCD"
data-slot="4397140188"></ins>
Now, you can see class="thisisfirstscript"
is repeated two times. So, when I am using the answered regex it is selecting from first class="thisisfirstscript"
to third class="thisisfirstscript"
, that means, class="thisissecondscript"
is also including. But, I want to select just particular class="thisisfirstscript"