in reply to Regex: Matching around a word(s)
After a successful match, determine by inspection where the matching term is in the string, and then set pos just after that. Perhaps something like this (untested):
while ($text =~ /$expr/g) { my ($prefix,$term,$suffix) = ($1, $2, $3); print "$prefix<b>$term</b>$suffix\n"; # update pos to just after $term pos() = pos() - length($suffix); }
-QM
--
Quantum Mechanics: The dreams stuff is made of
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex: Matching around a word(s)
by shotgunefx (Parson) on Dec 17, 2005 at 01:06 UTC |