I have the variable:
$line = "print var1, var2, var3";
var1
will always be present but the other var
's may not be.
I want to extract var1
and any other var
's that may appear.
I am currently using the following:
$line = "print var1, var2, var3";
if ($line =~ /\s*print\s*([A-Za-z0-9]+)(?=\s*,\s*([A-Za-z0-9]+))/){
print "$1\n";
while ($line =~ /\s*print\s*([A-Za-z0-9]+)(?=\s*,\s*([A-Za-z0-9]+))/g){
print "$2\n";
}
Not sure if I have over complicated this.. but the result of this is simply:
var1
var2
Instead of:
var1
var2
var3
Anyone know how I can achieve this?