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 back

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
eplace = "for(" + pattern + subStrPattern1_hasInitialization + ";" + subStrPattern2_hasRestTillEnd fNew.write( regObj.sub( strToFind, strToReplace ) ) else: fNew.write( l) } Here problem is , i am not getting backreferences using \1 and \2 The strin

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

Backreferences in python ?

2006-01-23 Thread Pankaj
I have something like below in perl and i am searching for equivalent in python: ::: 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 < 1

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 >

Re: backreferences

2005-09-28 Thread Amy Dillavou
ith 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 there something > &

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

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 \

backreferences

2005-09-28 Thread Amy Dillavou
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 there something else i have to