i = R003(201000)
描述:将i分成两部分“R003”和“201000”
import re
i = R003(201000)
num = re.match(r'(.*?)\((.*?)\)(.*?)',i).group(2)
name = re.match(r'(.*?)\((.*?)\)(.*?)',i).group(1)
print(num,name)
(.*?)\((.*?)\)(.*?)
其中(.*?)为最小匹配 \(和\)分别表示以(和)作为分隔来取字符串
re.match(r'(.*?)\((.*?)\)(.*?)',i)意思是分成两部分,括号外group(1)=R003和括号内group(2)=201000
match.group()返回匹配对象的一个或多个分组。
match.group(0)(或match.group())表示匹配的所有字段