[Tutor] Grep equiv.

Michael P. Reilly arcege@shore.net
Thu, 31 Aug 2000 13:20:30 -0400 (EDT)


> 
> > Is there a nice, easy, fast way of saying "if this
> > line/string/variable/array/whatever contains 'xxx' then do 
> > 'something'"
> 
> For literal strings use string.search()
> 
> For regular expressions use re.search()
> 
> eg:
> 
> import re
> if re.search('[pP]ython','My python script'):
>    print 'found it!'
> 
> 
> There are also substitution functions for search/replace operations...
> Read the re module docs.

There is also the "grep" module which gives you differing types of
regular expressions (does not support pcre).

If there is no need to use regular expressions, then use the string
module.  The overhead (even in Perl) of using a regular expression
engine is not always desirable.

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------