Find and Replace with Regex - Changes formatting? Help!

to clarify, if I have a situation like this:

1A or 1B

essentially a number and a letter next to each other with different formatting, say the number is bold and/or font size 9 and the letter is font size 12. I want to add a space between them anywhere they pop up in the document. So I created a regex find and replace like this:

Find: ([:digit:])([:alpha:])

Replace: $1 $2 ← with a space between them.

This works and is able to find all the situations and adds the space properly - BUT - whatever formatting attribute the digit has, now the alpha has as well, it changes the letter to have the same font size, bold, whatever that the digit had.

How can I do a find and replace like this but preserve the formatting of the letter, the $2 in this case.

Thanks in advance for any help!!

Unfortunately, we explicitly ignore zero-length matches, needed to use regex like (?<=[:digit:])(?=[:alpha:]), to replace with “ ” (single space) directly.

But you may only capture the letter, and use digit as a look-behind assertion:

(?<=[:digit:])([:alpha:])

and replace with “space then backreference to first capture” “ $1

1 Like

thanks so much, the second suggestion for find and a " $1" worked perfectly…and thanks for the quick reply.