in reply to Re: Re: Re: Turn Hate Mail to Love Letter: Regex Multi-Word/Phase Replace
in thread Turn Hate Mail to Love Letter: Regex Multi-Word/Phase Replace

$& is unnecessary. $1 is fine.

The $n in the key, say, 'lift $n up', is not static in a sense that if someone adds a new key/value pair, the $n will have to be changed. And it's not incremental by 1. It depends on how many bracketing constructs in total in the search pattern.

But your answer is in the right direction I think.

Thanks.
  • Comment on Re: Re: Re: Re: Turn Hate Mail to Love Letter: Regex Multi-Word/Phase Replace

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Turn Hate Mail to Love Letter: Regex Multi-Word/Phase Replace
by Skeeve (Parson) on Jun 26, 2003 at 07:40 UTC
    AHHH! Finally I got the problem!

    I forgot that you join all your keys to one regexp!

    I have to admit that I never used Tie:RegexHash. So I have no experience with it. Tell us when you finally had success.

      Regexp::Subst::Parallel seems to do the trick.
      use Regexp::Subst::Parallel; $_ = "Man Honoured at Harbour Centre by the Lift\n"; print; $_ = subst($_, qr/\b(h)arbour\b/i => '$1arbor', qr/\b(h)onour(.*?)\b/i => '$1onor$2', qr/\b(c)entre\b/i => '$1enter', qr/\b(L|l)ift\b/ => sub{$_=$_[1]=~/L/?"E":"e";$_."levato +r"} ); print; __END__ Man Honoured at Harbour Centre by the Lift Man Honored at Harbor Center by the Elevator