|
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(也就是第一条正则表达式),只能找到第一条语句。请问如何用正则,获得这四条语句。
请各位大佬帮忙写一个正则表达式,万分感谢。
|
|