正则表达式re
? 一、re模块的group和groups ? ? ? group 和 groups 是两个不同的函数 ? ? ? m.group()== m.group(0) ==?返回所有匹配到的字符 ? ? ? m.group(N) 返回第N组括号匹配到的字符 ? ? ? ?m.groups() 返回所有括号匹配到的字符,以元组格式存储 ? ? ?m.groups() = (m.group(1),m.group(2),....) ? ? ? 测试数据: ? ?? line = "Cats are smarter than dogs" matchObj.group: <built-in method group of _sre.SRE_Match object at 0x10f5ffe00> matchObj.group() : Cats are smarter than dogs matchObj.group() : Cats are smarter than dogs matchObj.group(1) : Cats matchObj.group(2) : smarter (‘Cats‘,‘smarter‘) Cats smarter (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |