Regexp help (HWV)

Whenever I have filenames with the following format:
Suite HWV 452 in Gm (I - Allemande)

I want to change it to:
Suite in Gm, HWV 452 (I - Allemande)

I wrote the following regexp to do this, but it doesn't work (no match is produced), even despite telling me that it DOES work:

Search for
HWV (\d+) in ([A-Ga-gm#]+)
Replace with:
in $2, HWV $1

(Note: the A-Ga-gm# accounts for things like G#m, Bb, D, etc. - shorthand ways of writing musical keys)

I double-checked that it is indeed "Replace with regular expression," it's searching the correct field, and it is NOT case-sensitive.

Edit: I just tried the same code with a quick action (Actions --> Actions (Quick)) and it worked. But when the code runs as part of a preset action, it doesn't work.

Everything looks good from what you're describing.

Are there any other actions running before this one in the group that might alter the filename to a format that is not matching anymore? If not, can you please post a screenshot of the "Replace with regular expression" dialog.