My regex:
联系人[::]\s{1,2}([^\s,,、]+)(?:[\s,,、]{1,2}([^\s,,、]+))*
Test string:
联系人: 啊啊,实打实大, 好说歹说、实打实 实打实大
Code
>>> import regex as re
>>> p = r'联系人[::]\s*([^\s,,、]+)(?:[\s,,、]{1,2}([^\s,,、]+))*'
>>> s = '联系人: 啊啊,实打实大, 好说歹说、实打实 实打实大'
>>> re.findall(p, s)
[('啊啊', '实打实大')]
# finditer
>>> for i in re.finditer(p, s):
... print(i.groups())
...
('啊啊', '实打实大')
Matchs:
You can test it here https://regex101.com/ (regex101 can't save regex now, so I have to post above pics)
I want all groups split by [\s,,、]
, but only match the first and last. I don't feel there is any wrong in my regex, though the result is wrong, this stuck me for half hour...
re
, you can access them with PyPi regex though. – Wiktor Stribiżewregex
, unfortunately same result. See my sample code. – Mithrilregex.search
if you expect a single match orregex.finditer
to get multiple matches, and then access the correspondinggroup
'scaptures
. See RegEx: Find all digits after certain string. – Wiktor Stribiżewfinditer
is just more memory efficient thanfindall
, the results are same. – Mithril