Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use Placeholders in PHP. But note, that this is not normal Regex behaviour, its special to PHP.:</p> <p><code>preg_match("/&lt;([^&gt;]+)&gt;(.+)&lt;\/\1&gt;/")</code> (the <code>\1</code> references the outcome of the first match)</p> <p>This will use the first match as condition for the closing match. This matches <code>&lt;a&gt;something&lt;/a&gt;</code> but not <code>&lt;h2&gt;something&lt;/a&gt;</code></p> <p>However in your case you would need to turn the "(" matched within the first group into a ")" - which wont work.</p> <p>Update: replacing <code>(</code> and <code>)</code> to <code>&lt;BRACE&gt;</code> AND <code>&lt;END_BRACE&gt;</code>. Then you can match using <code>/&lt;([^&gt;]+)&gt;(.+)&lt;END_\1&gt;/</code>. Do this for all Required elements you use: <code>()[]{}&lt;&gt;</code> and whatevs.</p> <p><code>(a) is as nice as [f]</code> will become <code>&lt;BRACE&gt;a&lt;END_BRACE&gt; is as nice as &lt;BRACKET&gt;f&lt;END_BRACKET&gt;</code> and the regex will capture both, if you use preg_match_all</p> <pre><code>$returnValue = preg_match_all('/&lt;([^&gt;]+)&gt;(.+)&lt;END_\\1&gt;/', '&lt;BRACE&gt;a&lt;END_BRACE&gt; is as nice as &lt;BRACKET&gt;f&lt;END_BRACKET&gt;', $matches); </code></pre> <p>leads to</p> <pre><code>array ( 0 =&gt; array ( 0 =&gt; '&lt;BRACE&gt;a&lt;END_BRACE&gt;', 1 =&gt; '&lt;BRACKET&gt;f&lt;END_BRACKET&gt;', ), 1 =&gt; array ( 0 =&gt; 'BRACE', 1 =&gt; 'BRACKET', ), 2 =&gt; array ( 0 =&gt; 'a', 1 =&gt; 'f', ), ) </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