42
6
The program should take a string as input and reverse the consonants in it, while keeping the order of vowels. All the letters will be lowercase, so you don't have to worry about casing. Examples follow.
Input:
a test case
.
The consonants here aret,s,t,c,s
. They should come in reversed order, i.e.s,c,t,s,t
and inserted back into the string to the same positions where the pre-reversed characters were located:a sect sate
.Input:
well-done
. Output:nedl-lowe
.- Input:
reverse the consonants
. Output:setenne sne cohtosarvr
.
This is the code golf, the shortest solution wins.
Y
should be considered vowel regardless of what it is and not reversed.
Anything, as well as numbers, punctuation, quotes, and other symbols (@#$%^&*(){}[]\|/<>~-_+=`
), could potentially appear in the input.
Very nice. Is
-[...]
specific to retina, or specific to .net regexes or is it a general regex feature that I've overlooked until now? – Digital Trauma – 2016-06-17T17:42:17.837@DigitalTrauma With this syntax I think it's specific to .NET. Other flavours have character class intersection as well, but then I think the syntax is usually
[...&&[^...]]
. – Martin Ender – 2016-06-17T17:44:00.763@MartinEnder I'll have to try these with sed and grep. Unlikely sed has it, but perhaps PCRE-mode grep. – Digital Trauma – 2016-06-17T17:52:23.840
1Perl 6 uses
<[b..z] - [eiouy]>
or<:Ll - [aeiouy]>
to do set difference – Brad Gilbert b2gills – 2016-06-18T01:34:08.940