Python正则表达式多组匹配
阿神
阿神 2017-04-17 15:14:00
0
2
777
阿神
阿神

闭关修行中......

reply all(2)
黄舟

The function of search is: from left to right, calculate whether there is a match, and if there is a match, return it. That is, as long as a match is found, it is returned. Therefore, at most one will be matched, not multiple.
findall can match all.

#!/usr/bin/python
# -*- coding: utf-8 -*- 

import re

str = 'xiaohong loves xiaoming,xiaozhu loves xiaoli,xiaopeng loves xiaozhao'

names = re.findall(r'(\S+) loves (\S+)(,|$)',str, re.I)

print names

if names:
    for group in names:
        print group[0], group[1]
大家讲道理

should use find_all()

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!