I’m looking for a regular expression to match all functions blocks (from start to end) in php files. For example:
function test_function($var) {
if ($var == 'somethin') {
print 'hi';
}
etc.
}
I need the start offset and end offset of the block. What regex can I use?
It is very very complicated and can’t be done with one regular expression.
You may think that you can easily match `the beginning of a function like this:
But you can’t because what is if there is this in a code?
So you should search on everything what isn’t quoted. So for excluding quoted strings you can use this regular expression:
The next thing you should do is counting all
{and}because you need to know when the function stops and I can’t think about any regular expression which can do this. So you need to do this with looping through.