title: Python regex map multiple matches to one
body: <p>I'd like a regex to return 'animal' if a string contains for instance 'dog', 'cat' or 'bird'.</p>
  <p>I can find them easily using:  <code>re.search('(dog|cat|bird)', mystring)</code></p>
  <p>but that will return 'dog', 'cat' or 'bird', for instance:</p>
  <pre><code>result = re.search('(dog|cat|bird)', 'a bag of birdseed')
  print(result)
  &lt;_sre.SRE_Match object; span=(9, 13), match='bird'&gt; 
  print(result[0])
  bird
  </code></pre>
  <p>Is it possible to craft a regex that will return 'animal' for any of the options?<br />
  So for the above example:</p>
  <pre><code>result = re.search(magic_regex, 'a bag of birdseed')
  print(result[0])
  animal
  </code></pre>
  <p>I am limited to <code>re.search</code> (existing, fixed code), the only freedom I have is the regex.</p>
  <p>The code that does the matching is inside a library (which I don't want to change unless I really have to). The library code is used to parse the response (using regexes) of (serial) commands we send to an embedded device. The responses are then mapped or converted to human readable values and displayed in a GUI-based configuration tool. Users can edit the values in the tool and write them back, without having to know any of the intricacies of the serial commands.</p>
  <p>We keep the regexes for all commands for each device in a database (a set of .ini files, containing hundreds of commands for several devices and their different firmware versions). The library code that does the matching takes the regex and the response of a command and returns the matching data (if any).</p>
  <p>The library code is now generic and can handle any type of response, but it can't 'map' multiple matching strings to one value, hence my question.
  If I can resolve my issue with a 'magic regex' then I don't have to touch the library. If that is not possible, I will have to look for a different solution, possibly changing the library code.</p>