简体   繁体   中英

python regex of group match

Here is my code:

import re

pattern_str = '(?P<style>[^|]*>)\|(?P<tags>[^|]*)'

p = re.compile(pattern_str)

m = p.match('OL|AAAAA')
a = m.group('style')  # AttributeError: 'NoneType' object has no attribute 'group'
print a

It doesn't work, how to fix it?

My python version is 2.6.5

你在style模式中有一个额外的>

pattern_str = '(?P<style>[^|]*)\|(?P<tags>[^|]*)'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM