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'

posted @ 2013-05-23 17:58  simon1024  阅读(163)  评论(0编辑  收藏  举报