找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 7914|回复: 0

[求助] 正则表达式方面的问题

0

主题

0

帖子

0

积分

贫民

积分
0
yu1995 发表于 2021-2-23 14:53:20 | 显示全部楼层 |阅读模式
2威望
本帖最后由 yu1995 于 2021-2-23 16:45 编辑

一个.c文件中,对文件中每一行进行正则表达式,来获取以下四条语句:

第一条:l4_print("the request type is \"initial request\".but the operation is not \"creat new qos rule\", the qos rule is default, need to release.");

第二条:ssa_print("the request type is %s",a);
第三条:nns_warn("the request type is %s",b");

第四条:nns_info("the request type is %s",c");

问题:如何通过正则表达式获取这四条语句。
我写的正则:pattern = r"""
                                       (?P<hls1>(\s+)(l4_print\((?P<content1>.*)?\;)) |
                                       (?P<hls2>(\s+)(ssa_print\((?P<content2>.*)?\;)) |
                                       (?P<hls3>(\s+)(nns_warn\((?P<content3>.*)?\;)) |
                                       (?P<hls4>(\s+)(ssa_print\((?P<content4>.*)?\;))
"""
然后我用findall 对C语言的每一行进行正则,但问题是 每次只匹配l4_print(也就是第一条正则表达式),只能找到第一条语句。请问如何用正则,获得这四条语句。

                                       
请各位大佬帮忙写一个正则表达式,万分感谢。


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表