-1

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"

Codelife
  • 185
  • 2
  • 11

1 Answers1

0

Try this:

/(?:<ins class="thisissecondscript")([\s\S]*)?(?:data-slot="4496122889"><\/ins>)/

Online Demo


Edit: According to updating the question, try this one:

/(?:<ins class="thisisfirstscript")([\s\S]*?)(?:data-slot="4397140188"><\/ins>)/gm

Online Demo

Shafizadeh
  • 9,960
  • 12
  • 52
  • 89
  • I have one more question. I have same script repeated multiple times. SO, when I am using it, it is selecting from start and end to all the other parts between them. Is there any other way that it will select only particular part at different places? – Codelife Mar 14 '16 at 15:03
  • Your question is kinda vague for me, I cannot understand it .. You have to create a new question on stackoverflow and ask your new question *(by a good explanation plus a few details)* – Shafizadeh Mar 14 '16 at 15:07
  • Hi, I have edited the question with explanation. Please have a look. – Codelife Mar 14 '16 at 15:17
  • Thanks for the answer. – Codelife Mar 14 '16 at 15:46