Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Generalizing a REGEX

by haukex (Bishop)
on Aug 08, 2020 at 19:02 UTC ( #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
Node Status?
node history
Node Type: note [id://11120504]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2021-04-12 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?