code: def match_reg(self, reg):
          
  
          mp = self.match_position
  
          match = reg.match(self.text, self.match_position)
          if match:
              (start, end) = match.span()
              if end == start:
                  self.match_position = end + 1
              else:
                  self.match_position = end
              self.matched_lineno = self.lineno
              lines = re.findall(r"\n", self.text[mp:self.match_position])
              cp = mp - 1
              while (cp >= 0 and cp < self.textlength and self.text[cp] != '\n'):
                  cp -= 1
              self.matched_charpos = mp - cp
              self.lineno += len(lines)
              #print "MATCHED:", match.group(0), "LINE START:",
              # self.matched_lineno, "LINE END:", self.lineno
          #print "MATCH:", regexp, "\n", self.text[mp : mp + 15], \
          #          (match and "TRUE" or "FALSE")
          return match
docs: match the given regular expression object to the current text
          position.
  
          if a match occurs, update the current text and line position.