1. 如果需要转义,开头加"r"
2. 分组获取
pat = re.compile(r'//\*\[@id="(.+)"\]')
matches = pat.findall('//*[@id="cc1"]')
for mat in matches:
print(mat)
输出:cc1
3. 位置查询
xpath = '123#456#cc1'
matches = re.finditer('#', xpath)
positions = [match.start() for match in matches]
for i in positions:
print(i)
输出:3,7