Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: regular expression search and replace

by hippo (Bishop)
on Nov 18, 2014 at 17:55 UTC ( [id://1107608]=note: print w/replies, xml ) Need Help??


in reply to regular expression search and replace

Your replacement has to be something tangible, not a pattern. However you can use the /e modifier to execute code in the replacement. Combining this with a capture group works like this:

#!/usr/bin/perl use strict; use warnings; my $line = "perlmonk is a gREat site. i loVE it.\n"; print $line; $line = ucfirst lc $line; print $line; $line =~ s/(\. [a-z])/uc($1)/eg; print $line;

Giving this output:

perlmonk is a gREat site. i loVE it. Perlmonk is a great site. i love it. Perlmonk is a great site. I love it.

Be sure to have a good read of perlre as regexes and the s/// function are bedrocks of Perl.

HTH, Hippo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 22:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found