in reply to Re: replacing strings using reg exp
in thread replacing strings using reg exp
One thing that you should be doing is using \Q and \E in your replacement. That is, you want to be replacing a literal abbreviation, not an abreviation-pattern. Also, you should limit that ".*". Granted, ".*?" would be good enough for most people, but I prefer to be explicit. Additionally, there is no reason to catch the latter half of the word being abreviated (so, drop the parenthesese). Last of all, you probably want to perform this replacement as many times as it occurs, so add a /g modifier:
$str =~ s/<\Q$abbr\E[^>]*>/<$abbr>/g;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: replacing strings using reg exp
by sauoq (Abbot) on Oct 17, 2003 at 05:47 UTC |