Home > other >  Python regex get characters before carriage return
Python regex get characters before carriage return

Time:01-19

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': ['[email protected]'], 'from': '"last, 
first" <[email protected]>', '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...

CodePudding user response:

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.

  • Related