Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It sounds like you want to allow newlines inside the parentheses, but not two or more newlines in a row. A typical regex for that might be </p> <pre><code>'~\(((?:.|\n(?!\r?\n))*)\)~' </code></pre> <p>But that doesn't allow for different kinds of newline (like <code>\r\n</code>, or just <code>\r</code>), nor does it match if there's horizontal whitespace (like spaces or tabs) on the "empty" line. It also doesn't make sure the parentheses are properly balanced; I don't know how important that is to you. Try this regex:</p> <pre><code>'~\(((?:[^\r\n()]|(?:\r\n|[\r\n])(?![ \t]*(?:\r\n|[\r\n]))|(?R))*+)\)~' </code></pre> <p>The first alternative ,<code>[^\r\n()]</code>, matches anything that's not a newline (or part of one) or a parenthesis.</p> <p>If that fails, <code>(?:\r\n|[\r\n])</code> tries to match one of the three kinds of newline, and the negative lookahead <code>(?![ \t]*(?:\r\n|[\r\n]))</code> makes sure the newline isn't followed by another newline, either immediately or with spaces or tabs between them.</p> <p>If the third alternative is reached, the next character should be either an open-paren, in which case <code>(?R)</code> tries to apply the whole regex recursively; or a close-paren, in which case the final <code>\)</code> finishes off the match (or pops up to the next higher level of recursion).</p> <p>Of course, this doesn't account for the possibility of escaped parentheses, Unicode whitespace and line separators, or any number of other refinements, but I'm really just demonstrating how to enforce the <em>no more than one newline</em> rule, and to explain why it's more difficult to do than you might have expected.</p>
 

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