Reverse the consonants
Retina, 22 21 20 17
O#^`[b-z-[eiouy]]
Try it online!
1 byte thanks to Leaky Nun!
4 bytes thanks to Martin!
O
means sort, and #
means to sort by numeric value. Since none of the matched characters will ever have a numeric value, all letters have the same weight: 0. ^
means to reverse the order of the sorted values, which thanks to stable sorting means the values are reversed.
The -[...]
means to do the setwise difference between the outer character class and this inner class. This is part of .NET and you can read more at the MSDN.
Python 2, 86 bytes
s='';c=()
for x in input():b='{'>x not in'aeiouy'<x;s+=b*'%s'or x;c=(x,)*b+c
print s%c
Takes input as a string in quotes. Iterates through the input, replacing each consonant with %s
in s
. The tuple c
stores the consonants encountered in reversed order. Then, string formatting replaces the %s
's in s
with the consonants in c
.
Thanks to Sp3000 for the consonant check, which saved 4 bytes over listing the consonants.
Jelly, 22 20 bytes
Øaḟ“<1Ṛż»
e€¢œpżf¢Ṛ$
Try it online!
How it works
Øaḟ“<1Ṛż» Helper link. No arguments.
Øa Yield the lowercase alphabet/
“<1Ṛż» Decompress that string, yielding "oui aye".
ḟ Filter; remove the characters from the right string from the left one.
e€¢œpżf¢Ṛ$ Main link. Argument: s (string)
¢ Call the helper link, yielding the string of all consonants.
e€ Test each character of s for membership.
œp Partition s at members/consonants.
$ Combine the three links to the left into a monadic chain.
f¢ Filter by presence in the consonant string.
Ṛ Reverse the result.
ż Zipwith; interleave chunks of non-consonants and reversed consonants.