Pip, 17 bytes
aR-C+XL.C+XD{c.b}
Takes input as a command-line argument. Try it online!
Explanation
This uses the standard regex-replacement strategy, somewhat golfed. Explanation of golfing tricks will appear shortly
The regex is -C+XL.C+XD
, which evaluates to `(?i)([a-z]+)(\d+)`
:
XL Preset regex variable for lowercase letter: `[a-z]`
+ Apply + to the regex: `[a-z]+`
C Wrap the regex in a capturing group: `([a-z]+)`
- Apply the case-insensitive flag: `(?i)([a-z]+)`
XD Preset regex variable for digit: `\d`
+ Apply + to the regex: `\d+`
C Wrap the regex in a capturing group: `(\d+)`
. Concatenate the two regexes: `(?i)([a-z]+)(\d+)`
The replacement is {c.b}
, a callback function that concatenates the second group (c
) and the first group (b
). (The first argument to the function, a
, contains the whole match.)
This is three bytes shorter than the naive aR`(\D+)(\d+)``\2\1`
.