Board logo

标题: [问题求助] 【已解决】下面Python代码运行报错 求报错原因 [打印本页]

作者: c755731262    时间: 2015-11-9 23:46     标题: 【已解决】下面Python代码运行报错 求报错原因

本帖最后由 c755731262 于 2015-11-12 02:15 编辑
  1. # -*- coding:UTF-8 -*-
  2. import re
  3. #p=re.compile(r'(abc)\1')
  4. #m=p.match('abcabcab')
  5. #print (m.group(0))
  6. #print (m.group(1))
  7. #print (m.group())
  8. p=re.compile(r'(?p<one>abc)(?p=one)')
  9. m=p.search('abcabcab')
  10. print (m.group('one'))
复制代码

作者: c755731262    时间: 2015-11-9 23:54

回复 1# c755731262


    字母p要大写,才不会报错,但不能输出  print (m.group(2))第二个分组所对应的内容
作者: 依山居    时间: 2015-11-10 08:31

你先看看资料吧。
  1. """
  2. Python正则表达式
  3. http://www.runoob.com/python/python-reg-expressions.html
  4. Python正则表达式指南
  5. http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html
  6. """
  7. import re
  8. a="abcabcab"
  9. reg=re.compile(r"(abc)\1")
  10. aresult=re.match(reg,a)
  11. print(aresult)
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2