Fellow Monasterians:
Sorry for the convoluted title, but as penitence for using an "&" and no "()" in calling subroutines in my early scripts, I'm hoping to edit my code with a regular expression.
my $call = "&somesub"; $call =~ s/(&)(\w+(\([\"\w]*\))?)/$2/;
OR
my $call = "&somesub("foobar")"; $call =~ s/(&)(\w+(\([\"\w]*\))?)/$2/;
I want to end up with somesub() or somesub("foobar") respectively.
Question: How can I alter my regex to add the "()"s if they are not there, and leave them if they are? Thanks!
In reply to Regex to add text if text is missing by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |