Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: regex find and replace with a twist

by james28909 (Deacon)
on Jul 17, 2018 at 12:16 UTC ( #1218652=note: print w/replies, xml ) Need Help??


in reply to regex find and replace with a twist

Heres a short example that does that:

use strict; use warnings; my $modified_string; while ( read DATA, my $buf, 1 ) { $modified_string .= "[$buf]" unless $buf !~ /[a-zA-Z]/; } print $modified_string; __DATA__ this is a test

And yet another example!:

use strict; use warnings; my $string = "this is a test"; my $modified_string = $string =~ s/([a-zA-Z])/\[$1\]/gr; print $modified_string;

EDIT: changed pattern match to include only characters a-z in first example.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2020-04-04 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (32 votes). Check out past polls.

    Notices?