title: Type of compiled regex object in python
body: <p>What is the type of the compiled regular expression in python?</p>
  
  <p>In particular, I want to evaluate</p>
  
  <pre><code>isinstance(re.compile(''), ???)
  </code></pre>
  
  <p>to be true, for introspection purposes.</p>
  
  <p>One solution I had was, have some global constant <code>REGEX_TYPE = type(re.compile(''))</code>, but it doesn't seem very elegant.</p>
  
  <p><strong>EDIT:</strong> The reason I want to do this is because I have list of strings and compiled regex objects. I want to "match" a string against list, by</p>
  
  <ul>
  <li>for each string in the list, try to check for string equality.</li>
  <li>for each regex in the list, try to check whether the string matches the given pattern.</li>
  </ul>
  
  <p>and the code that I came up with was:</p>
  
  <pre><code>for allowed in alloweds:
      if isinstance(allowed, basestring) and allowed == input:
          ignored = False
          break
      elif isinstance(allowed, REGEX_TYPE) and allowed.match(input):
          ignored = False
          break
  </code></pre>