sherab has asked for the wisdom of the Perl Monks concerning the following question:
DEXX and AREX are stored in a hash like so.... "DEXX" => "AREX", "AREX" => "CUBE"
The regex I have is this.....
foreach (keys %hashstore){ $doc=~s!\b($_)\b!$1/$hashstore{$_}!ig; }
What's happening is that "DEXX" is being replaced with "DEXX/AREX" ok but when "DEXX/AREX" is encountered the regex is replacing "DEXX/AREX" with "DEXX/AREX/CUBE" when it should only be replacing "AREX" when it finds it as a standalone word not as part of another combination like "DEXX/AREX"
I thought that a negative lookback might work . i.e.....
foreach (keys %hashstore){ $doc=~s#(?<!/)\b($_)\b#$1/$hashstore{$_}#ig; }
No luck though
It seems to detect "/" as a word boundary. Has anyone encountered this or know of a fix around it? Many thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting around "/" as a word boundary
by ikegami (Patriarch) on Aug 12, 2010 at 04:22 UTC | |
by AnomalousMonk (Archbishop) on Aug 12, 2010 at 05:01 UTC | |
by renshui (Novice) on Aug 12, 2010 at 08:34 UTC | |
by AnomalousMonk (Archbishop) on Aug 12, 2010 at 08:48 UTC | |
by ikegami (Patriarch) on Aug 12, 2010 at 16:14 UTC |