Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You probably could use greed killer <code>?</code> in your code expression (more info here: <a href="https://stackoverflow.com/questions/7227664/matching-text-between-delimiters-greedy-or-lazy-regular-expression">Matching text between delimiters: greedy or lazy regular expression?</a> ), so if you have a code like this:</p> <pre><code>&lt;code&gt;foo&lt;/code&gt; another &lt;code&gt;bar&lt;/code&gt; </code></pre> <p>It will match just <code>foo</code> and <code>bar</code> not <code>foo&lt;/code&gt; another &lt;code&gt;bar</code>, also you should use <a href="http://php.net/manual/en/function.preg-match-all.php" rel="nofollow noreferrer"><code>preg_match_all()</code></a> (with flag <code>PREG_OFFSET_CAPTURE</code>) and write your own parser. Or rather use <a href="http://php.net/manual/en/function.preg-replace-callback.php" rel="nofollow noreferrer"><code>preg_replace_callback()</code></a> like this:</p> <pre><code>// Just strtolower example (this would do formatting) function myCallback( $matches){ return strlower( $matches[2]); } $string = preg_replace_callback("/(&amp;lt;code&amp;gt;).*?(&amp;lt;\/code&amp;gt;)/si", 'myCallback', $string) </code></pre> <p>Note the question-mark in <code>.*?</code>. You also should use <code>s</code> and <code>i</code> modifiers so your code would work on codes like this:</p> <pre><code>lorem ipsum &lt;code&gt; foo &lt;/code&gt; bar </code></pre> <p>If you need validation you can use this:</p> <pre><code>$string = preg_replace("/(&amp;lt;code&amp;gt;).*?(&amp;lt;\/code&amp;gt;)/si", '', $string); if( (strpos( $string, '&lt;code') !== false) || (strpos( $string, '&lt;/code') !== false){ echo 'Invalid code'; } </code></pre>
 

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