Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Generalizing a REGEX

by haukex (Archbishop)
on Aug 08, 2020 at 19:02 UTC ( [id://11120504]=note: print w/replies, xml ) Need Help??


in reply to Generalizing a REGEX

You can anchor the regex to the end of the string with $. See perlrequick, perlretut, and perlre. Note the /r modifier I'm using is only available in Perl 5.14 (from 2011) and up.

$ perl -le 'print for map { s/\.(\d+)$/($1)/r } qw/cat.1 ld.so.conf.5 +/' cat(1) ld.so.conf(5)

Update: See also Re: How to ask better questions using Test::More and sample data

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-25 21:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found