Regex | SoloLearn: Learn to code for FREE!



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?

7/31/2020 4:27:43 AM

Mr. 12

3 Answers

New Answer


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.


I think this should work Watch this series, although it is javascript, coz regex is the same, he explains realllly well


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.