title: QRegEx to highlight everything between braces
body: <p>I'm trying to get a regular expression to match the text between curly braces</p>
  
  <p><a href="https://stackoverflow.com/questions/2403122/regular-expression-to-extract-text-between-square-brackets">The following SO question</a>. Gave me a start but it's not working for me. And I'm not sure what I'm doing wrong.
  Consider the following:</p>
  
  <pre><code>The {quick} brown fox {jumped over the} lazy old {dog}. While {the [0ld] man} spoke {to the} gardener.
  </code></pre>
  
  <p>What I am trying to do is to match all the text between the curly braces, so I can highlight them. The expression</p>
  
  <pre><code>\{(.*?)\}
  </code></pre>
  
  <p>did not work for me. I'm not sure why.
  I'm using python 2.10/pyqt, and the QRegExp class of pyqt on Windows.</p>
  
  <p>Can anyone point out what I'm doing wrong. </p>
  
  <p>Just to add more detail, this time with some code. consider the following</p>
  
  <pre><code>import sys
  from PyQt4.QtGui import *
  from PyQt4.QtCore import *
  
  class MyHighlighter( QSyntaxHighlighter ):
  
      def __init__( self, parent, theme ):
  
          QSyntaxHighlighter.__init__( self, parent )
          self.parent = parent
          keyword = QTextCharFormat()
  
  
          self.highlightingRules = []
  
          # keyword
          brush = QBrush( Qt.darkBlue, Qt.SolidPattern )
          keyword.setForeground( brush )
          keyword.setFontWeight( QFont.Bold )
          keywords = QStringList( [ "break", "else", "for", "if", "in", 
                                    "next", "repeat", "return", "switch", 
                                    "try", "while" ] )
          for word in keywords:
  
              pattern = QRegExp("\\b" + word + "\\b")
              rule = HighlightingRule( pattern, keyword )
              self.highlightingRules.append( rule )
  
  
          # braces
          singlebraces = QTextCharFormat()
          pattern = QRegExp( "\{(.*?)\}" )
          pattern.setMinimal( False )
          brush = QBrush( Qt.darkRed, Qt.SolidPattern )
          singlebraces.setForeground( brush )
          rule = HighlightingRule( pattern, singlebraces )
          self.highlightingRules.append( rule )
  
      def highlightBlock( self, text ):
  
          for rule in self.highlightingRules:
  
              expression = QRegExp( rule.pattern )
              index = expression.indexIn( text )
              while index &gt;= 0:
                  length = expression.matchedLength()
                  self.setFormat( index, length, rule.format )
                  index = text.indexOf( expression, index + length )
              self.setCurrentBlockState( 0 )
  
  class HighlightingRule():
  
      def __init__( self, pattern, format ):
  
          self.pattern = pattern
          self.format = format
  
  class TestApp( QMainWindow ):
  
      def __init__(self):
  
          QMainWindow.__init__(self)
          font = QFont()
          font.setFamily( "Courier" )
          font.setFixedPitch( True )
          font.setPointSize( 10 )
          editor = QTextEdit()
          editor.setFont( font )
          highlighter = MyHighlighter( editor, "Classic" )
          self.setCentralWidget( editor )
          self.setWindowTitle( "Syntax Highlighter" )
  
  
  if __name__ == "__main__":
      app = QApplication( sys.argv )
      window = TestApp()
      window.show()
      sys.exit( app.exec_() )
  </code></pre>
  
  <p>Well when i run this and type anything between curly braces, it does not get highlighted red. Just for good measure I have left the keywords in to show that the code does do syntax highlighting. </p>
  
  <p>Note: 
  I did try the expression <code>\{(.*?)\}</code> on the website and yes it did work, but not clear why the expression isn't working in the code.</p>