Find Replace all numbers to subscript BUT NOT OTHER NUMBERS

This is related to

In the above link, it changes the numbers as subscripts even in places like “There were 2,485 people”.
Another issue for me is I would like to use REPLACE box’s Format button to say Automatic Subscript.

I am looking for a way to search & replace only in the cases of 1,2 &3 below, and not in rest of the cases below. Because rest of them do not fit a pattern for a subscript of a number for me.

Please let me know the regular expression to use, AND the REPLACE string to Use.
Sometimes I need to use a subset of digits, so d does not work for me. I have to use [1-4] etc.

ab5sdf (only one number inside a word, match and replace as subscript)
asdf5 (only one number at the end of a word, match and replace as subscript)
as3Pc9ss5 (numbers occur by themselves, so match and replace as subscript)
4th
52nd
2,485
5 to 7 people
in 5, 6, or 7 days
05/22/2023
5-7-23
5.7.23
5.1
1-First Section
asdf343fff
asdf3333

Create a subscript character style.

Find all:
[a-z][1-9][^0-9](?: [a-z]|[:space:])?

Then:
[x] Current selection only
Find all:
[1-9]

Apply the subscript character style.

It skips strings followed by a line break. Is it intentional?

Could we find the digits of interest in one step? For example:

Find all:
(?<=[a-z])[1-9](?=\b|[a-z])

1 Like

This worked well.
In the 2nd step,
I could choose the Format button and specify Subscript, Auto and use $0 as replacement value.

The first findAll included some case like -
5. fifth point.

This selects just the numbers, which helps to do the replace in same step.
Thank you.