Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: A little golfing challenge: Replacing letters with numbers

by rsFalse (Hermit)
on Feb 21, 2019 at 17:27 UTC ( #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
Node Status?
node history
Node Type: note [id://1230317]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2020-01-24 14:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?