Backreferences in python ?

Gerhard Häring gh at ghaering.de
Mon Jan 23 10:38:11 EST 2006


Pankaj wrote:
> [...]
> ****************************************
> What i tried in python was::
> ****************************************
> 
> f = open( "./1.c", "r")
> fNew = open( "./1_new.c", "w")
> for l in f:
>         print l
>         lineno = lineno + 1
>         strToFind = "for\((.*)\;(.*)"
> [...]

Regular expressions are not handled automatically in Python the way you 
apparently think they are.

In Python, you will need to use the "re" module:

http://docs.python.org/lib/module-re.html

-- Gerhard



More information about the Python-list mailing list