in reply to Regex is eating up whitespace
Aside from this probably being an inadequate approach to solving the actual problem, you are using character set matches where you need anchors. Changing [^<] to (?<!<) avoids matching the preceding character, but ensures that it isn't <. Try:
$text =~ s/\b(?<!<)S\.(?!=)/<S.=initial>/g;
Remember that the substitution replaces all the characters matched so you must either capture and insert any "extra" matched characters or not match them in the first place (anchors don't "match" characters in this sense).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex is eating up whitespace
by gatito (Novice) on Sep 29, 2008 at 23:42 UTC | |
by GrandFather (Saint) on Sep 29, 2008 at 23:49 UTC | |
by dragonchild (Archbishop) on Sep 30, 2008 at 13:18 UTC |