Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: regex find and replace with a twist

by james28909 (Deacon)
on Jul 17, 2018 at 12:16 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1218652]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-04-23 18:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found