Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: A little golfing challenge: Replacing letters with numbers

by rsFalse (Chaplain)
on Feb 21, 2019 at 17:27 UTC ( [id://1230317]=note: print w/replies, xml ) Need Help??


in reply to A little golfing challenge: Replacing letters with numbers

haukex: "... solution to produce such a regex character set for any given list of letters."

E.g.
perl -0777 -ne 'print "" . ( join "", "A" .. "Z" ) =~ s/[^$_]/ /gr =~ +s/\B\w+\B/-/gr =~ s/ +//gr'
OUTPUT:
A-IK-NP-TVWYZ
Corresponding link.

For having dashes between VW and YZ I tried to use this:
perl -0777 -ne 'print "" . ( join "", "A" .. "Z" ) =~ s/[^$_]/ /gr =~ +s/(?<=\w)\w*(?=\w)/-/gr =~ s/ +/ /gr'
..but somehow got: A--IK--NP--TV-WY-Z :(

And these worked fine:  s/(?<=\b\w)\w*(?=\w\b)/-/gr,  s/(\w)\w*(\w)/$1-$2/gr --> A-IK-NP-TV-WY-Z :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-19 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found