why the output have assitanc;instead,of assistance? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

3rd Mar 2018, 3:21 PM
Azazul Islam
Azazul Islam - avatar
2 Answers
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\.])
18th Jun 2018, 4:52 AM
Cristian Baeza Jimenez
Cristian Baeza Jimenez - avatar
0
here the code, in the final part of the regex a \w* was added. https://code.sololearn.com/cjyZH1vsuggd/?ref=app
18th Jul 2018, 2:53 AM
Cristian Baeza Jimenez
Cristian Baeza Jimenez - avatar