Change
$ref =~ s/(\$\S)/\$sym->{'$1'}/g
to
$ref =~ s/(\$\S+)/\$sym->{'$1'}/g
Of course, that won't work too well if the person uses
$x+$y=7
instead of
$x + $y = 7
so you might want to use
$ref =~ s/(\$\w+)/\$sym->{'$1'}/g
I presume you will later eval this string? I don't think that's a very good idea. I would indeed recommend using a parser.
In reply to Re: Regular expression match and substitution
by ikegami
in thread Regular expression match and substitution
by pip9ball
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |