正则表达式 小甲鱼
四年级 记叙文 632字 96人浏览 shynie018

(五)

>>> m = re.match("([abc])+", "abc") >>> m.groups()

('c',)

>>> m = re.match("(?:[abc])+", "abc") >>> m.groups()

()

>>> p = re.compile(r'(?P<word>\b\w+\b)')

>>> m = p.search( '(((( Lots of punctuation )))' )

>>> m.group('word')

'Lots'

>>> m.group(1)

'Lots'

InternalDate = re.compile(r'INTERNALDATE "'

r'(?P<day>[ 123][0-9])-(?P<mon>[A-Z][a-z][a-z])-'

r'(?P<year>[0-9][0-9][0-9][0-9])'

r' (?P<hour>[0-9][0-9]):(?P<min>[0-9][0-9]):(?P<sec>[0-9][0-9])' r' (?P<zonen>[-+])(?P<zoneh>[0-9][0-9])(?P<zonem>[0-9][0-9])' r'"')

>>> p = re.compile(r'(?P<word>\b\w+)\s+(?P=word)')

>>> p.search('Paris in the the spring').group()

'the the'