import re
teststr = 'i am a man, my name is xxx! you can call me dad. understand everyone?'
def testexchange(teststr):
print(teststr)
strsearch = re.search(".*?[,.?!]", teststr)
it = re.finditer('.*?[,.?!]', teststr)
resultlist =[]
for match in it:
resultlist.append(" ".join(str(match.group())[0:-1].strip().split(" ")[::-1]))
resultlist.append(str(match.group())[-1] + " ")
print("".join(resultlist).strip())
================ RESTART: C:/Users/win 10/Desktop/stempstr.py ================
i am a man, my name is chenge! you can call me baba. ok everyone?
man a am i, chenge is name my! baba me call can you. everyone ok?