I have some random text like:

>>>text= \
"""import sys  

n = int(sys.argv[1]) ;;print "blbalbalbalabllalbaa"

replace me i in range(1,n) {print "numbers:";;replace me j in range(1,3) {print j} ;;print i ;;replace me k in range(1,3) {print k} ;;print "end!"}

replace me n < 5 {print n ;;print "youragenious"}   
"""

i'd like to change all ";;" to ";;____" or ";;fourrandomthings" or whatever but only inside of {...}
i tried:

>>> p=re.compile(' {([^;]*);;([^;]*)}')
>>> print p.sub(r' {\1;;    \2}',text)
import sys  

n = int(sys.argv[1]) ;;print "blbalbalbalabllalbaa"

replace me i in range(1,n) {print "numbers:";;    replace me j in range(1,3) {print j} ;;print i ;;replace me k in range(1,3) {print k} ;;    print "end!"}

replace me n < 5 {print n ;;    print "youragenious"}

it's still not what i need...please help

What you show isn't python, I think. I think you should start with a hello world python program, in a text file, then extend it one step at a time until you get where you need to go. Working in the python line editing environment is fine for a quick little test, but you have to re-enter everything every time you need a change, so the text script file is much better for programming.

Hint: Python string with \1 or \2 in it should be spelled r'\2' for instance (note the leading r) ... or you need to escape the backslash: '\\2'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.