search a string

Carl J. Van Arsdall cvanarsdall at mvista.com
Thu Apr 20 17:28:24 EDT 2006


david brochu jr wrote:
> Hello,
>  
>  
> I have a text file with the following string:
> ['\r\n', 'Pinging www.ebayyy.com <http://www.ebayyy.com/> 
> [207.189.104.86 <http://207.189.104.86>] with 32 bytes of data:\r\n', 
> '\r\n', 'Request timed out.\r\n', '\r\n', 'Ping statistics for 
> 207.189.104.86:\r\n', '    Packets: Sent = 1, Received = 0, Lost = 1 
> (100% loss),\r\n']
>  
>  
> How would I search to find out if the string contained "Request" and 
> report if "Request" was found or not in the string?
Well, there really are two ways you could go about it depending on what 
you are more comfortable with.

One way:

import re
line = '<...>' # all that stuff from above
regExp = re.compile('Request')
if regExp.match(line):
  print 'I found requested'


or you can use one of the string modules, I suggest hitting up the 
documentation on python.org if you wish to know string functions.




-- 

Carl J. Van Arsdall
cvanarsdall at mvista.com
Build and Release
MontaVista Software




More information about the Python-list mailing list