title: Is there a method to omit nested parentheses in regex?
body: <p>I'm writing a regex function for PHPs' <code>preg_match_all</code> to find all <code>ifs(...)</code> with all its contents from a string. (In my example I've got only one ifs, as it's not re root of the problem.)</p>
  
  <p>Here's what I've got so far:</p>
  
  <p>Pattern: <code>/ifs\(.*?\)/i</code></p>
  
  <p>String: <code>=iferror(ifs(OR("foo", "bar"),"a",OR("tar", "scar"),"b",OR("lar"),"d"),"c")</code></p>
  
  <p>Current output: <code>ifs(OR("foo", "bar")</code></p>
  
  <p>Expected output: <code>ifs(OR("foo", "bar"),"a",OR("tar", "scar"),"b",OR("lar"),"d")</code></p>
  
  <p>The problem: regex finds first closing parentheses.</p>
  
  <p>Where am I going wrong? And how would you tackle nested parentheses?</p>
  
  <p>Demo: <a href="https://regex101.com/r/SgBqbW/1" rel="nofollow noreferrer">https://regex101.com/r/SgBqbW/1</a></p>