简体   繁体   中英

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...

The Python regular expression you are looking for is

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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