Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is pretty far outside the normal use of regexes. Although it might be possible, it's far easier, far more maintainable, and possibly computationally faster to split this problem up into subproblems.</p> <p>First of all, regexes can't handle arbitrarily-nested comments, which are valid HTML.</p> <p>Consider first splitting the content up into an array of paragraphs, looping through the paragraphs to find the third paragraph that doesn't contain an image, and inserting your text after that.</p> <p>If you really have to use regexes, something like <code>^.*?((((&lt;p(&gt;|\W)(?!&lt;img(&gt;|\W))))(.(?!&lt;img(&gt;|\W)))*?(&lt;/p\W*&gt;).*?)){3}</code> would match what you want once you strip comments.</p> <p>Explanation:</p> <p>The <code>^</code> is to ensure that it only matches up to the first three paragraphs that match the pattern, and not the last 3 (or every 3). Then, it reluctantly matches anything up until the real pattern starts. The real pattern then matches a <code>&lt;p&gt;</code> tag (avoiding other tags that start with p, but still allowing for attributes) so long as it is not immediately followed by an <code>&lt;img&gt;</code> tag, and then reluctantly matches any character so long as it is not followed by an <code>&lt;img&gt;</code> tag until it gets to a <code>&lt;/p&gt;</code> close tag. This means that since no character between <code>&lt;p&gt;</code> and <code>&lt;/p&gt;</code> has and <code>&lt;img&gt;</code> tag following it, there is no <code>&lt;img&gt;</code> tag between <code>&lt;p&gt;</code> and <code>&lt;/p&gt;</code>. After that, the pattern reluctantly matches any other characters so that it allows for anything between non-image paragraphs, but so that it doesn't match non-image paragraphs themselves, and so that it doesn't match anything that's not strictly needed. This is then repeated 3 times, to get the third such paragraph.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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