in reply to Searching for text not inside a hyperlink
Result:$_ = <<'--'; Oh no, Anti-globalization activists are coming! Globalization is rejected by... -- use Regex::PreSuf; %links = ( 'globalization' => '/encyclopedia/Globalization/index.html', 'anti-globalization' => '/encyclopedia/Anti-Globalization/index.htm +l' ); my $re = presuf(keys %links); s/($re)/<a href="$links{lc $1}">$1<\/a>/gio; print;
Regex::PreSuf is a module to build a regex out of a list of words. It'll escape metacharacters, so the resulting regex will always just do literal lookups.Oh no, <a href="/encyclopedia/Anti-Globalization/index.html">Anti-glob +alization</a> activists are coming! <a href="/encyclopedia/Globalization/index.html">Globalization</a> is +rejected by...
Do note how I made the replacement case-insensitive, making the keys of the hash lower case, and doing the lookup with lc $1 — in addition to use of the /i switch.
|
|---|