Extract email from string instead of whole line from string
python, regex
Solution
`.group(0)` returns the whole string. You want `.group(1)`:
email = re.search("Reason: 550 (.*?)... No such user", demo_text).group(1)
Problem
I am attempting to grab just the email address from a string of text using Regex. How can I get my simple code to extract just the email address and not the whole line? ``` demo_text = """hsds hjdsjd ksdkj Reason: 550 abc@gmail.com... No such user sdhjsdjh """ # the following code extracts the whole line "Reason: 550 abc@gmail.com... No such user" # how do I just extract "abc@gmail.com"? email = re.search("Reason: 550 (.+)... No such user", demo_text).group(0) ```