Code:
str = \'
A
B\'
print(re.sub(r\'\\w$\', \'\', str))
It is expected to return
The non-greediness won't start later on like that. It matches the first
and will non-greedily match the rest, which actually need to go to the end of the string because you specify the $
.
To make it work the way you wanted, use
/
\w$/
but usually, it is not recommended to use regex to parse HTML, as some attribute's value can have <
or >
in it.