0

I have 2 paragraphs, with html tag <p class="mb-40px"></p> Inside this tag there is text and another <p..> tag

I need to find and delete html tag which is contained in main tag <p class="mb-40px"></p>

Example:

<p class="mb-40px">Miracles every day <p lang="ro-RO" align="JUSTIFY">being at la home, the poet Petru Iliesu made an international appeal to condemn the killing of demonstrators, shot on the streets of town.</p>

<p class="mb-40px">The pleasure we feel after reading a book is different from the pleasure of tasting a dish <p class="dis23">. In the first case, pleasure is disinterested, having no particular purpose, as a release from external preoccupations.</p>

Output

<p class="mb-40px">Miracles every day being at la home, the poet Petru Iliesu made an international appeal to condemn the killing of demonstrators, shot on the streets of town.</p>

<p class="mb-40px">The pleasure we feel after reading a book is different from the pleasure of tasting a dish. In the first case, pleasure is disinterested, having no particular purpose, as a release from external preoccupations.</p>

My regex is not too good:

FIND: (?:<p class="mb-40px">|\G)\S*\K(?:\h+<\s*(\w+)[^/>]*>)(?=.*</p>)

Replace by: (leave empty)

2 Answers 2

2

Here is your modified formula which works on my side:

<p class="mb-40px">.*\K(?:\h+<\s*(\w+)[^\/>]*>)(?=.*<\/p>)

  • you don't need to use ?:< and \G if you anyway use \K
  • \S* would work only if you'd have only one word without spaces between the tags, use .* instead
  • / need to be escaped: \/

enter image description here

and here is an even shorter expression:

<p class="mb-40px">.*\K<p[^>]+>

1

Yes, I manage myself to find solution:

FIND: (?-i:<p class="mb-40px">|\G(?!^))(?s:(?!</p>).)*?\K(?-i:<\s*(\w+)[^/>]*>)

REPLACE BY: LEAVE EMPTY

so, if I want to find/replace something framed in two other sections, the generic regex will be:

(?-i:REGION-START|\G(?!^))(?s:(REGION-FINAL).)*?\K(?-i:FIND REGEX)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .