fork download
  1. import re
  2.  
  3. string = """
  4. #Text which I want to keep intact
  5. #Lots of text
  6. #Lots and lots of text
  7. #Lots and lots and lots of other text
  8.  
  9. #Then in-between the file I have text in this format which I want to operate on:
  10.  
  11. ginstance
  12. {
  13. name ginstance_053D627B1349FA0BC57
  14. node "FINDME"
  15. inherit_xform on
  16. visibility 255
  17. blah
  18. blah
  19. blah
  20. }
  21.  
  22. ginstance
  23. {
  24. name ginstance_053D627B1349FA0BC57
  25. node "DONTFINDME"
  26. inherit_xform on
  27. visibility 255
  28. blah
  29. blah
  30. blah
  31. }
  32. """
  33.  
  34. rx = re.compile("""
  35. ginstance\s*\{
  36. [^}]*
  37. (?:node\ "FINDME")
  38. [^}]*
  39. \}
  40. """, re.VERBOSE)
  41. string = re.sub(rx, '', string)
  42. print string
Success #stdin #stdout 0.01s 8968KB
stdin
Standard input is empty
stdout
#Text which I want to keep intact
#Lots of text 
#Lots and lots of text 
#Lots and lots and lots of other text 

#Then in-between the file I have text in this format which I want to operate on:

 

ginstance 
{ 
 name ginstance_053D627B1349FA0BC57 
 node "DONTFINDME" 
 inherit_xform on 
 visibility 255 
blah 
blah 
blah 
}