需求:
将result=123变成123=result
方法:
1. Python
a.
import re
subject = "result=123"
reobj = re.compile(r"(\w+)=(\w+)")
result = reobj.sub(r"\2=\1",subject)
print result
b.
import re
subject = "result=123"
reobj = re.compile(r"(?P<left>\w+)=(?P<right>\w+)")
result = reobj.sub(r"\g<right>=\g<left>",subject)
print result
2. Tcl
set subject "result=123"
regsub -all "(\\w+)=(\\w+)" $subject "\\2=\\1" result
puts "$result"