in reply to Regex to strip, keep, or add—depending
$_ =~ s/^&(\w+)([\(\)]*)/$1()/;
The above matches : An amperstand (at the beging of the string/line) followed by one or more letters or numbers (in group 1) folowed by and number of parenthesis (in group 2).
&foobar("asdf") # will only match &foobar(
It appears you are trying to use perl code to modify perl code. This is not usually a safe idea (unless you really really know what you are doing). The Perl parser is very complex, and will account for more things than you are going to want to deal with in a regex.
The having been said... the following I believe will do as close as I can get to what you mean
s/^(&\w+)\(?((?:(?!;).)*)\)?;/$1($2);/
But keep in mind... this will fail in a situation like:
&foobar("a", 5, qw(dave jen anne matt), map({tr/[a-z]/[A-Z]/; $_;} @mi +xedCase));
The perl parser will understand that.... but the supplied regex will not.
They say that time changes things, but you actually have to change them yourself.
Andy Warhol
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex to strip, keep, or add—depending
by bradcathey (Prior) on Aug 06, 2005 at 15:53 UTC | |
by JediWizard (Deacon) on Aug 06, 2005 at 16:08 UTC |