Re: Backreferences in python ?

2006-01-24 Thread Sion Arrowsmith
Pankaj <[EMAIL PROTECTED]> wrote: >search for :for ( i = 0; i < 10; i++) >Replace with: for( printf( "10" ), i =0; i < 10; i++) >Where 10 is the line no. >f = open( "./1.c", "r") >fNew = open( "./1_new.c", "w") >for l in f: >print l >lineno = lineno + 1 >strToFind = "f

Re: Backreferences in python ?

2006-01-23 Thread Giovanni Bajo
Pankaj wrote: Perl ::: > *** > while( ) > { > > line = $_; > > pattern = "printf\( \"$lineNo \" \),"; > > line =~ s/"for(.*)\((*.)\;(.*)/for$1\($pattern$2\;$3/g; > } > > This is used to > > search for :for ( i = 0; i < 10; i++) > Replace with: for( printf( "10" ),

Re: Backreferences in python ?

2006-01-23 Thread Paul McGuire
"Pankaj" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > I have something like below in perl and i am searching for equivalent > in python: > > ::: Perl ::: > *** > while( ) > { > > line = $_; > > pattern = "printf\( \"$lineNo \" \),"; > > line =~ s/"for(.*)

Re: Backreferences in python ?

2006-01-23 Thread Duncan Booth
Pankaj wrote: > Here problem is , i am not getting backreferences using \1 and \2 > You wrote: > subStrPattern1_hasInitialization = "\1" "\1" is the way to create a string containing a control-A character. What you actually wanted was a string containing a backslash and a "1", so you need e

Re: Backreferences in python ?

2006-01-23 Thread Pankaj
I got my answer if ( m != None ) : subStrPattern1_hasInitialization = m.group(1) subStrPattern2_hasRestTillEnd = m.group(2) str = subStrPattern1_hasInitialization + subStrPattern2_hasRestTillEnd strToReplace = "for(" + pattern + str This gave me my soluti

Re: Backreferences in python ?

2006-01-23 Thread Pankaj
My tries have with re have not yielded results:: { strToFind = 'for*;*' ## Converting int to string, i.e. line no. to string lineNoClone = lineno pattern = "printf(\"" + str( lineNoClone) + "\")," regObj = re.compile( strToFind) m = regObj.searc

Re: Backreferences in python ?

2006-01-23 Thread Gerhard Häring
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\((.*)\;(.

Re: Backreferences in python ?

2006-01-23 Thread Jean-Paul Calderone
On 23 Jan 2006 07:18:13 -0800, Pankaj <[EMAIL PROTECTED]> wrote: > > [snip] >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\((.*)\;(.*)" > >## For Converting int to

Re: backreferences

2005-09-28 Thread Peter
Iain King wrote: >Amy Dillavou wrote: > > >>Can someone help me with understanding how python uses backreferences? >>I need to remember the item that was last matched by the re engine but i >>cant seem to understand anything that I find on backreferences. if I >>want to access the last match do

Re: backreferences

2005-09-28 Thread Amy Dillavou
George and Iain - Thanks for your help!!! It worked for me, and that book seems to be really useful =) A.D On Wed, 2005-09-28 at 11:16 -0400, George Sakkis wrote: > "Amy Dillavou" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > Can someone help me with understanding how python u

Re: backreferences

2005-09-28 Thread George Sakkis
"Amy Dillavou" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Can someone help me with understanding how python uses backreferences? > I need to remember the item that was last matched by the re engine but i > cant seem to understand anything that I find on backreferences. if I > w

Re: backreferences

2005-09-28 Thread Iain King
Amy Dillavou wrote: > Can someone help me with understanding how python uses backreferences? > I need to remember the item that was last matched by the re engine but i > cant seem to understand anything that I find on backreferences. if I > want to access the last match do i use \number or is the