简体   繁体   English

Python 正则表达式在回车前获取字符

[英]Python regex get characters before carriage return

I am not very good at regexs and would appreciate some help.我不太擅长正则表达式,希望得到一些帮助。 I have converted a dict to a string:我已将字典转换为字符串:

message = "{'msg_id': 'XXXX', 'to': ['me@yahoo.com'], 'from': '"last, 
first" <me@yahoo.com>', 'subject': 'Fwd: Your certificate', 
'body':['Cert Name: capture.this.com\r', 'Requestor: Lastname, Firstname']}"

I would like a regex that would capture capture.this.com , I have tried Cert Name:(.*/\r) with no luck...我想要一个可以捕获capture.this.com的正则表达式,我已经尝试过Cert Name:(.*/\r)但没有运气......

The Python regular expression you are looking for is您要查找的 Python 正则表达式是

r"Cert Name: (.*)\\r"

While the RegEx matches all characters up to and including the carriage return, the capture group will only be the capture.this.com .虽然 RegEx 匹配所有字符直至并包括回车符,但捕获组将仅为capture.this.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM