@H_502_0@需求:
@H_502_0@将result=123变成123=result
@H_502_0@方法:
@H_502_0@1. Python
@H_502_0@a.
@H_502_0@import re
@H_502_0@subject = "result=123"
@H_502_0@reobj = re.compile(r"(\w+)=(\w+)")
@H_502_0@result = reobj.sub(r"\2=\1",subject)
@H_502_0@print result
@H_502_0@
@H_502_0@b.
@H_502_0@import re
@H_502_0@subject = "result=123"
@H_502_0@reobj = re.compile(r"(?P<left>\w+)=(?P<right>\w+)")
@H_502_0@result = reobj.sub(r"\g<right>=\g<left>",subject)
@H_502_0@print result
@H_502_0@
@H_502_0@2. Tcl
@H_502_0@set subject "result=123"
@H_502_0@regsub -all "(\\w+)=(\\w+)" $subject "\\2=\\1" result
@H_502_0@puts "$result" 原文链接:https://www.f2er.com/regex/361710.html