REGEX - Matching the PHP echo statement
I've been racking my head for a while now, thought I'd bring my problem here encase anyone can easily spot how to solve my problem.
I need a regex to match any PHP echo statement. i.e. it must be able to match the following examples below
Here is what I've come up with so far.
echo "this is some text";
echo "this is some text with a ; semi colon in the middle";
echo "this is some text with \" double quotes in the middle";
echo 'this is some text with single quotes in the middle';
echo "string" . $variable;
echo $variable . "string";
echo $variable . 'string';
This regex matches everything but then fails when you don't use strings in your echo statement but you use variables instead.
This regex matches variables but then fails when theres a semi colon inside a string.
$regex = "/echo\s+(.*?[(\".*?(?<!\\\\)\")|('.*?(?<!\\\\)')])*?;/si";
Is there one regex which matches all possibilities? I can't see it.
$regex = "/echo\s+.*?;