0

I have the following example text in which I want to find the section that contains MY-TEXT

<SECTION>
  Not important random text
  Not important random text
  Not important random text
  Not important random text
  Not important random text
</SECTION>

<SECTION>
  Not important random text
  Not important random text
  MY-TEXT
  Not important random text
  Not important random text
  Not important random text
</SECTION>

<SECTION>
  Not important random text
  Not important random text
  Not important random text
  Not important random text
  Not important random text
</SECTION>

My approuch was using this regex:

(?<=<SECTION>)([\w\W]+?MY-TEXT[\w\W]+?(?=<\/SECTION>))

But this is selecting the first section as well. I have tried different approaches, but I can't find any solution.

Other results on StackOverflow only refers to section that don't have multiple lines and the approach is entirely different.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
P. Bogdan
  • 1
  • 1

0 Answers0