[Python-il] re.search question (was Re: problem in script)

Shai Berger shai at platonix.com
Tue Jan 19 18:39:56 IST 2010

On Tuesday 19 January 2010, Yitzhak Wiener wrote:
> Hi Guys,


> May I ask you a question?

Of course you may. It would be better, though, if you had opened a new thread 
instead of pretending to reply to an old one.

> [...]
> Can you advice please how it should be done?
> [...]
> pattern = re.compile ("MultiProgPage_Code at c0 - SECTION HEADER")
> result = pattern.search(s)

The Python interpreter has a built-in "help" function. You can use it with 
"bound methods" -- methods belonging to objects; thus, 
$ python
Python 2.5.4 (r254:67916, Nov 19 2009, 19:46:21)
[GCC 4.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> pat = re.compile('.')
>>> help(pat.search)

Will show you

    search(string[, pos[, endpos]]) --> match object or None.
    Scan through string looking for a match, and return a corresponding
    MatchObject instance. Return None if no position in the string matches.

That is, you can specify a starting point right after the searched string, as 
a second parameter to search().

In case you read the help and find it to terse, you should refer to the 
documentation at http://docs.python.org/library/re.html#re.RegexObject.search

Hope this helps,

More information about the Python-il mailing list