title: How to return string representation of re.search() in python
body: <p>I am aware that [re.search(pattns,text)][1] in python  method takes a regular expression pattern and a string and searches for that pattern within the string. If the search is successful, search() returns a match object or None otherwise.</p>
  
  <p>My problem however is, am trying to implement this using OOP (class) i want to return a string representation of the results of the matches whether true or none
  or any other form of representation(readable) not this <strong>&lt;__main__.Expression instance at 0x7f30d0a81440></strong> below are two  example classes : Student and Epression. The one using <strong>__str__(self)__</strong> works fine but i cannot figure out how to get the representation funtion for <strong>re.search()</strong>.
  Please someone help me out.</p>
  
  <pre><code>import re   
  
  class Expression:
      def __init__(self,patterns,text):
  
          self.patterns = patterns
          self.text = text
  
  
      def __bool__(self):
      # i want to get a readable representation from here
          for pattern in self.patterns:
             result = re.search(pattern,self.text)
             return result
  
  
  
   patterns = ['term1','term2','23','ghghg']
   text = 'This is a string with term1 23 not ghghg the other'
  
   reg = Expression(patterns,text)
   print(reg)
  
  
   class Student:
  
      def __init__(self, name):
  
         self.name = name
  
  
     def __str__(self):
      # string representation here works fine
          result = self.name 
          return result
  
   # Usage:
  
    s1 = Student('john')
    print(s1)
  
  
   [1]: https://developers.google.com/edu/python/regular-expressions
  </code></pre>