I have a text where digits appear in every possible way. For example,
text = "hello23 the2e are 13 5.12apples *specially_x00123 named 31st"
I want to replace all digits with '#'s except the ones in a special pattern starting with *, a word, underscore, any character, and number such that *\w+_[a-z]\d+ (i.e., *specially_x00123).
I've tried to use lookaround syntax and non-capturing group but can't find a way to exactly change this to as below
text_cleaned = "hello## the#e are ## #.##apples *specially_x00123 named ##st"
I can use a pattern like below:
p1 = r'\d(?<!\*\w+_\w+)'
Then, it complains like this; "look-behind requires fixed-width pattern"
I tried to use non-capturing group:
p2 = r'(?:\*[a-z]+_\w+)\b|\d'
It takes out the special token (*specially_x000123) and all the digits. I think this is something that I may include in the solution, but I can't find how. Any ideas?