in reply to Re^2: a small regexp question
in thread a small regexp question
So... assuming this is actually perl, and not something else using PCREs, then this actually seems to work:
my $string = "a_sample_string"; $string =~ m/(?{ tr|_| | })(.*)/; print $1;
That said, this is terribly fragile and dangerous. I wouldn't actually do that. You are essentially reaching out from the inside regex and altering the match variable before trying to match. It does manage to meet your criterion, though.
Update: Remember that this is actually a destructive match, though... you aren't just returning $1, but also altering the match input, wherever that comes from. This will fail if the match input is immutable.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: a small regexp question
by fizbin (Chaplain) on Jul 29, 2005 at 14:01 UTC |