gatito has asked for the wisdom of the Perl Monks concerning the following question:
I've tried using word boundaries, but beyond that I'm not sure what to do. Thanks for advice in advance.
code
#!/usr/local/bin/perl $text = "Paulson and Federal Reserve Chairman Ben S. Bernanke proposed + the plan after the collapse"; $text =~ s/\b[^<]S\.[^=]\b/\<S\.=initial\>/g; print "$text\n";
actual result ( no space before < and after > ):
desired result ( preserves spaces ):Paulson and Federal Reserve Chairman Ben<S.=initial>Bernanke proposed +the plan after the collapse
Paulson and Federal Reserve Chairman Ben <S.=initial> Bernanke propose +d the plan after the collapse
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex is eating up whitespace
by GrandFather (Saint) on Sep 29, 2008 at 22:12 UTC | |
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 | |
|
Re: Regex is eating up whitespace
by moritz (Cardinal) on Sep 29, 2008 at 21:51 UTC | |
|
Re: Regex is eating up whitespace
by JavaFan (Canon) on Sep 29, 2008 at 21:48 UTC |