0
why the output have assitanc;instead,of assistance?
pattern = r"([\w\.-]+)@([\w\.-]+)(.[\w\.])+" str = "Please contact info@sololearn.com for assistance" match = re.search(pattern, str) if match: print(match.group()) output: info@sololearn.com for assistanc
2 Respostas
0
At first I did not understand why happens this. To understand I put the regex and text in this page https://regexr.com/.
It gave the same result. Finally I see that last group represents words of 2 characters and then "+" means 1 o more. If you count from the characters from " for" to the last letter "e" that is odd. so the solution put another "." before the last "[ ]":([\w\.-]+)@([\w\.-]+)(..[\w\.])
0
here the code, in the final part of the regex a \w* was added. https://code.sololearn.com/cjyZH1vsuggd/?ref=app