python re replace group reference and unicode escape conflict
09:27 06 Oct 2026

I am working on a latin to N'ko translator.

I get a warning for this type of code:

text=re.sub(r'([ߊߍߋߌߐߏߎ][\u07F2]*)\u0300','\g<1>\u07EC',text,0,re.UNICODE|re.MULTILINE)

SyntaxWarning: invalid escape sequence '\g'

I get an error for this correction on the second term:

text=re.sub(r'([ߊߍߋߌߐߏߎ][\u07F2]*)\u0300',r'\g<1>\u07EC',text,0,re.UNICODE|re.MULTILINE)
re.error: bad escape \u at position 5

a double slash \\u instead of \u : no warning and no error message but the whole string u07EC gets inserted, not the unicode character.

What am I missing here ?

Thank you all !

python regex unicode