I am trying something very simple. The string I have is
Hello a1234 World a3456 Python a4567 a4567
I want to find all the words which
- start with a
- Have four numbers after it
I want to replace the small 'a' in such occurrences with a 'A'.
re.sub("\ba\d\d\d\d\b','A\d\d\d\d',str)
I know the above regex is wrong. I want the output as
Hello A1234 World A3456 Python A4567 A4567
How do I replace only a portion of the match I get?
Edited with a fresh string
str_check='''
Helloa1256
Hello a1256
Hello a1256
Hello a1256
'''
x=re.sub('\ba(?=\d\d\d\d\b)','A',str_check)
print(x)
Why is the the whole word search failing here?