Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Lookahead/Lookbehind Regular Expression...

by hdb (Prior)
on Dec 19, 2013 at 17:15 UTC ( #1067839=note: print w/ replies, xml ) Need Help??

in reply to Lookahead/Lookbehind Regular Expression...

I would prefer a two step approach avoiding look(ahead|behind|around) assertions: first find patterns like a repeat of letter followed by a dot, then remove the dots and replace the pattern. Like this:

use strict; use warnings; my $str = "a history of u.s. coast guard aviation. M.C. Esher"; $str =~ s/\W\K((\w\.)+)/ $1 =~ s{\.}{}gr /ge; print "$str\n";

The \W\K at the beginning is required to avoid matching "am.c.". It will also match a single occurence of letter followed by dot but that can be easily fixed by requiring two or more repetitions.

Update: removed the unnecessary non-capturing ?: from the regex.

Comment on Re: Lookahead/Lookbehind Regular Expression...
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067839]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2016-04-30 00:14 GMT
Find Nodes?
    Voting Booth?
    :nehw tseb si esrever ni gnitirW

    Results (441 votes). Check out past polls.