Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Search and replace logic

by !1 (Hermit)
on Nov 19, 2003 at 03:44 UTC ( [id://308216]=note: print w/replies, xml ) Need Help??


in reply to Search and replace logic

s/(n(?i:s|c)e)/$1 ^ "nse" ^ "nce"/gie;

Of course, that's only if you want to keep its case (mad props to Abigail-II for the nifty trick :-). However, if you want a more general mechanism for mapping particular words to other words and don't mind about the case:

my %word_map = ( nce => "nse", nse => "nce" ); my $re = join "|", map qr/\Q$_/i, keys %word_map; s/($re)/$word_map{lc $1}/ge; print

That would be a more general mechanism even though it doesn't keep case.

Hope this helps.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-19 10:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found