import re arg = "jing4 gong1 sang1 zi3" arg_count = arg.count(" ") patten ="([a-z]*)\d\s?"*(arg_count+1) print patten arg_compile = re.compile(patten) match_obj = arg_compile.search(arg) print match_obj.groups()
import re arg = "jing4 gong1 sang1 zi3" arg_count = arg.count(" ") patten ="([a-z]*)\d\s?"*(arg_count+1) print patten arg_compile = re.compile(patten) match_obj = arg_compile.search(arg) print match_obj.groups()