I want to find all occurrences of parent::, the called function and the parameter
For example:
parent::test( new ReflectionClass($this) );
But the following regular expression doesn’t match the outer brackets – only the inner ones:
parent::(.*)\((.*)\);
Array /* output */
(
[0] => parent::test( new ReflectionClass($this) );
[1] => test( new ReflectionClass
[2] => $this)
)
How do I have to modify the pattern?
That is for a PHP script, so I can use some other string functions, too.
What you are trying to do is generally not possible with regular expressions. To do what you want, you have to be able to count things, which is something regular expressions can’t do.
Making the matching greedy will eventually lead to matching too much, especially when you are supporting multiple line input.
To replace every occurence of parent:: you probably don’t have to match the method call exactly, maybe it is enough to match something like this:
Then you can replace the parent:: with something else and use the first matching group to put whatever was in the document at this position.