More fun with case-(very)-sensitive strings
Retina, 19 bytes
Retina doesn't have a direct way to reverse a string, but we can do it by exploiting the sorting stage:
O^#`[a-z]
O^#`[A-Z]
Sort (O
), reading them as numbers (#
), and then reverse the ordering (^
), of all the strings matching the given regex (lowercase letters for the first line, and uppercase letters for the second).
This works because when we try to read strings without numeric characters as numbers they get treated as 0
, so all the characters have the same value for sorting. Since sorting is stable they are left in the same order, and reversing them returns the original string reversed.
Try it online!
Perl, 45 bytes
44 bytes of code + -p
flag.
for$c(u,l){@T=/\p{L$c}/g;s/\p{L$c}/pop@T/ge}
Try it online!
Unicode characters classes \p{Lu}
and \p{Ll}
matches respectively uppercase and lowercase letters.
So /\p{L$c}/
will return the list of all upper (or lower) case letters (and store it inside @T
).
And then, the regex s/\p{$c}/pop@T/ge
will replace each (upper, then lower case) letter by the last letter of @T
while removing it from @T
.
JavaScript (ES6), 74 73 71 70 bytes
f=
s=>(g=r=>s=s.replace(r,_=>a.pop(),a=s.match(r)))(/[A-Z]/g,g(/[a-z]/g))
<input oninput=o.textContent=f(this.value)><pre id=o>
Edit: Saved 1 byte thanks to @Arnauld.