2008/10/2 aditya shukla <[EMAIL PROTECTED]> > Hello folks , > > I trying to match a pattern in a string , i am new in using re .This is > what is happening > > When i do this > > p = re.compile('(\[&&NHX:)') > >>> m = p.match("[&&NHX:C=0.195.0]") > >>> print m > <_sre.SRE_Match object at 0x013FE1E0> > --- thus i am able to find the match > but when i use the string > > m = p.match("-bin-ulockmgr_server:0.99[&&NHX:") > >>> print m > None > -i am not able to find the match . > > Can someone help me here. > > Thanks > > Aditya > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, You may want to check the re documantation - chapter Matching vs Searching
http://docs.python.org/library/re.html#matching-vs-searching "... match checks for a match only at the beginning of the string ..." >>> import re >>> p = re.compile('(\[&&NHX:)') >>> p.match("[&&NHX:C=0.195.0]") <_sre.SRE_Match object at 0x01C2FEA0> >>> p.match("-bin-ulockmgr_server:0.99[&&NHX:") >>> p.search("-bin-ulockmgr_server:0.99[&&NHX:") <_sre.SRE_Match object at 0x01C2FF60> >>> p.findall("-bin-ulockmgr_server:0.99[&&NHX:") ['[&&NHX:'] >>> hth vbr
-- http://mail.python.org/mailman/listinfo/python-list