s = 'xyzA*12*pqR*stB*HS*lmN*opA*45*a4N*gB*SD*drtU*ghy'
import re
pattern = re.compile('A\\*(.*?)(\\*.*?B\\*)(.*?)\\*')
pattern.sub('A*\\3\\2\\1*', s)
How to switch two elements in string using Python RegEx?