Python中的RegEx不匹配

极客
with open(file_path, 'r') as logs:
    for line in logs.readlines():
        reg = re.compile('publishing service \/rest\/service\/\w+-\w+-\w+-\w+-\w+\state\s\w+\b.*');
        print(reg.search(line.strip()));

我正在使用上面的正则表达式代码进行模式匹配。我的字符串如下

2019-01-17 19:41:40.445 UTC,INFO ,myapp:761,publishing service /rest/service /4ce2c885-3690-48ba-a1cb-bb1762859a39 state

但是我的代码无法匹配此字符串。有什么建议吗?

这个

您错过了s并使用r原始字符串):

reg = re.compile(r'publishing service/rest/service\s*/\w+-\w+-\w+-\w+-\w+\sstate\b');
#         here __^                                                  here __^  

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章