Skip to content

Instantly share code, notes, and snippets.

@TomZhuPlanetart
Created February 21, 2024 09:51
Show Gist options
  • Save TomZhuPlanetart/6a5b1f67478dc8eb600eab59f25ed578 to your computer and use it in GitHub Desktop.
Save TomZhuPlanetart/6a5b1f67478dc8eb600eab59f25ed578 to your computer and use it in GitHub Desktop.
Regular Expression To Match nested function call

With the help of recursion clause (https://www.regular-expressions.info/recurse.html),

(\w*|\w*::\w*)\((?:\s*((?<=\()|(?<!\(),)\s*((?R)|\$\w+)\s*)*\)

This expression matches function calls like below:

Registry::initRegistry(registry( $a, $b, abc( $a, $b, $c), $d));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment