X-Received: by 10.224.87.2 with SMTP id u2mr6800007qal.4.1362937350293; Sun, 10 Mar 2013 10:42:30 -0700 (PDT) X-Received: by 10.50.135.41 with SMTP id pp9mr579363igb.2.1362937350092; Sun, 10 Mar 2013 10:42:30 -0700 (PDT) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!usenet.blueworldhosting.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!t2no457802qal.0!news-out.google.com!o5ni454qas.0!nntp.google.com!dd2no483392qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Sun, 10 Mar 2013 10:42:29 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=218.248.12.170; posting-account=utVMDgoAAACBclB38JUYjL1LjVN2Gha6 NNTP-Posting-Host: 218.248.12.170 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Regular expression problem From: mukesh tiwari Injection-Date: Sun, 10 Mar 2013 17:42:30 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 2340 Xref: csiph.com comp.lang.python:41022 Hello all=20 I am trying to solve this problem[1] using regular expression. I wrote this= code but I am getting time limit exceed. Could some one please tell me how= to make this code run faster.=20 import re if __name__ =3D=3D "__main__": n =3D int ( raw_input() ) c =3D 1 while c <=3D n : email =3D filter ( lambda x : x !=3D None , [ re.search ( '[^~!@#= $%^&*()<>?,.]*[a-zA-Z0-9][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9.= _][a-zA-Z0-9._]*@[a-zA-Z0-9]+.(com|edu|org|co.in)[^~!@#$%^&*()<>?,.a-zA-Z0-= 9]*' , x ) for x in raw_input().split(' ') ] ) t =3D len ( email ) print 'Case #' + str ( c ) + ': ' + str ( t ) for i in xrange ( t ): print email[i].group() c +=3D 1 Also rather than breaking the string at space, I tried to use findall but I= am not getting correct result.=20 >>> re.findall ( '[^~!@#$%^&*()<>?,.]*[a-zA-Z0-9][a-zA-Z0-9._][a-zA-Z0-9._]= [a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._]*@[a-zA-Z0-9]+.(com|edu|org|co.in)[^= ~!@#$%^&*()<>?,.a-zA-Z0-9]*[ ]+','mukeshtiwari.iiitmmmm@gmail.com mukeshtiw= ari.iiitmmmmm@gmail.com') ['com'] I am suppose to get [ mukeshtiwari.iiitmmm@gmail.com , mukeshtiwari.iiitmmm= @gmail.com] ? Regards Mukesh Tiwari [1] http://www.spoj.com/problems/MAIN12C/