How to add prefix to specific strings?

I have hundreds of text strings, like

‘=Tf0-Yr1t/0.5*St’

Now I want to add “#” before the strings that starts with English letter, maybe number in the middle and/or ends with number, as below.

‘=#Tf0-#Yr1t/0.5*#St

@Xiaofei_Ying Try this:

import re

OUT = [re.sub('(?=[A-Z])','#',x) for x in IN[0]]
4 Likes

@Xiaofei_Ying If you don’t have a well defined word pattern which always starts with an UPPER case letter then this should do the trick.

import re

OUT = [re.sub(r'(?=\b[^\W\d])','#',x) for x in IN[0]]
1 Like

Anyone can try this. Hope it helps
Renombrar parámetro de familia.dyn (41.4 KB)