regex for python like preg_match of php

  Python adds an extension syntax to Perl’s extension syntax. If the first character after the question mark is a P,
  you know that it’s an extension that’s specific to Python. Currently there are two such extensions: (?P<name>...) defines a named group,
  and (?P=name) is a backreference to a named group.
  >>> p = re.compile(r'(?P<word>\b\w+\b)')
  >>> m = p.search( '(((( Lots of punctuation )))' )
  >>> m.group('word')
'Lots'
 >>> m.group(1)
'Lots'

原文地址:https://www.cnblogs.com/simonote/p/3095309.html