Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Try this</strong></p> <pre><code>(?is)&lt;p&gt;.+?&lt;/p&gt;(?=.*?&lt;/div&gt;) </code></pre> <p><strong>Code</strong></p> <pre><code>$subject =~ s!(?is)&lt;p&gt;.+?&lt;/p&gt;(?=.*?&lt;/div&gt;)!!g; </code></pre> <p><strong>Explanation</strong></p> <pre><code>" (?is) # Match the remainder of the regex with the options: case insensitive (i); dot matches newline (s) &lt;p&gt; # Match the characters “&lt;p&gt;” literally . # Match any single character +? # Between one and unlimited times, as few times as possible, expanding as needed (lazy) &lt;/p&gt; # Match the characters “&lt;/p&gt;” literally (?= # Assert that the regex below can be matched, starting at this position (positive lookahead) . # Match any single character *? # Between zero and unlimited times, as few times as possible, expanding as needed (lazy) &lt;/div&gt; # Match the characters “&lt;/div&gt;” literally ) " </code></pre> <p><strong>UPDATE</strong></p> <p><em>Change your code as follows:</em></p> <pre><code>#!/usr/bin/perl use strict; use warnings; my $string = &lt;&lt;STRING; &lt;div id="main"&gt; hellohello &lt;div id="text"&gt; nokay. &lt;p&gt;This is p1, SHUD B replaced&lt;/p&gt; Alright &lt;p&gt;This is p2, SHUD B replaced&lt;/p&gt; Yes 2 &lt;p&gt;this is P3, SHUD B replaced&lt;/p&gt; Okay done bye &lt;/div&gt; bye &lt;p&gt;this is not under the div whose id is text and SHUDN'T b replaced&lt;/p&gt; &lt;/div&gt; STRING my $str_bak = $string; print "Sring is : \n$string\n\n"; $string =~ s!(?is)&lt;p&gt;.+?&lt;/p&gt;(?=.*?&lt;/div&gt;)!!g;; print "Sring now is : \n$string\n\n"; </code></pre> <hr> <p>And that script gives exactly what is built for. Showing all contents except <code>&lt;p&gt;</code> elements within <code>div</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload