Regex | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Regex

in the given program, it is printing even the mail has got mailmail but, it has to be true only if it has only one gmail,or emali, or mail. after that it is also taking comcom inin but it has to print only it has one com or one in after the dot. ex : [email protected] #output : wrong mail [email protected] #output : wrong mail [email protected] #output : wrong mail [email protected] #output : right mail How Can We Do Like That? https://code.sololearn.com/c29lRf3Vv4J7/?ref=app

31st Jul 2020, 4:27 AM
Mr. 12
Mr. 12 - avatar
3 Answers
+ 2
Mr. 12 The reason things like mailmail and comcom are being matched is because of the "+" you put after the (mail|gmail...). The "+" means that 1 or more of that group (or whatever the "+" is acting on) can be matched. Really, the "+" doesn't need to be there (as maf 's code shows). Nice work though! 👍 Update: Also, you must change the square brackets to round, or else things like [email protected] will be matched. Characters in square brackets can appear in any order.
31st Jul 2020, 3:44 PM
Russ
Russ - avatar
+ 1
I think this should work https://code.sololearn.com/cJNDp4MmpipE/?ref=app https://www.youtube.com/playlist?list=PL4cUxeGkcC9g6m_6Sld9Q4jzqdqHd2HiD Watch this series, although it is javascript, coz regex is the same, he explains realllly well
31st Jul 2020, 5:09 AM
maf
maf - avatar
+ 1
yes Russ , i have created another program after that which returns all the mailid's in a string or in a line. this program will return all the mailid's try this : tell me if you got any bugs. https://code.sololearn.com/cQQt0kqfHfiB/?ref=app https://code.sololearn.com/c67Qu4zkf2eu/?ref=app
31st Jul 2020, 4:07 PM
Mr. 12
Mr. 12 - avatar