I am trying to parse codes inside a function. The code is placed between { and } and it can span several lines obviously.
Coming from a different educational background, I don't have a formal education in computer engineering and I haven't passed a course on compilers. So, please excuse me if my question is basic or if there's no regex solution to this problem. If there's another solution, like context-free grammars, feel free to mention it and explain it please.
So, I have come up with this regular expression:
/(.*\s+function\s+.*)\{(\n|.*)+\}/
The problem with this expression is that if we have multiple such expressions, it will capture all of them in one group. For example, the following text will be captured as one group instead of two separate groups containing only the code blocks:
private function blah() {
\\ CODE #1: some code that has to be captured
}
private function blah2(string $test) {
\\ CODE #2: some other code that has to be captured separately
}
Is it possible to use regex to capture the two blocks separately? My regex engine is PHP 7.4+.