Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
402 views
in Technique[技术] by (71.8m points)

python的正则怎么同时匹配两个不同结果?

category = re.findall('(?<=compatible; )([^/]+)', line)
category = re.findall('(?<="-" ")([^"]+)', line)

怎么让category同时匹配这两个正则里面的数据

两句正则怎么并到一起

因为这样写的话他只认下面那个正则


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

re.findall('(?<=compatible; )([^/]+) | (?<="-" ")([^"]+) ', line)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...