title: python regular expression: match either one of several regular expressions
body: <p>I have a string and three patterns that I want to match and I use the python <code>re</code> package. Specifically, if one of the pattern is found, output "Dislikes", otherwise, output "Likes". Brief info about the three patterns:</p>
  
  <blockquote>
    <p>pattern 1: check if all character in string is uppercase letter</p>
    
    <p>pattern 2: check if consecutive character are the same, for example,
    <code>AA</code>, <code>BB</code>...</p>
    
    <p>pattern3 : check if pattern <code>XYXY</code> exist, <code>X</code> and <code>Y</code> can be same and
    letters in this pattern do not need to be next to each other.</p>
  </blockquote>
  
  <p>When I write the pattern separately, the program runs as expected. But when I combine the 3 patterns using alternation <code>|</code>, the result is wrong. I have check the stackoverflow post, for example, <a href="https://stackoverflow.com/questions/6613831/merge-several-regular-expressions-into-one-re">here</a> and <a href="https://stackoverflow.com/questions/39613091/regular-expression-match-either-of-two-conditions">here</a>. Solution provided there do not work for me.</p>
  
  <p>Here is the original code that works fine:</p>
  
  <pre><code>import sys
  import re
  
  if __name__ == "__main__":
      pattern1 = re.compile(r"[^A-Z]+")
      pattern2 = re.compile(r"([A-Z])\1")
      pattern3 = re.compile(r"([A-Z])[A-Z]*([A-Z])[A-Z]*\1[A-Z]*\2")
  
      word = sys.stdin.readline()
      word = word.rstrip('\n')
      if pattern1.search(word) or pattern2.search(word) or pattern3.search(word):
          print("Dislikes")
      else:
          print("Likes")
  </code></pre>
  
  <p>If I combine the 3 pattern to one using the following code, something is wrong:</p>
  
  <pre><code>import sys
  import re
  
  if __name__ == "__main__":
  
      pattern = r"([A-Z])[A-Z]*([A-Z])[A-Z]*\1[A-Z]*\2|([A-Z])\1|[^A-Z]+"
  
      word = sys.stdin.readline()
  
      word = word.rstrip('\n')
      if re.search(word, pattern):
          print("Dislikes")
      else:
         print("Likes")
  </code></pre>
  
  <p>If we call the 3 patterns <code>p1</code>, <code>p2</code>, and <code>p3</code>, I also tried the following combination:</p>
  
  <pre><code>pattern = r"(p1|p2|p3)"
  pattern = r"(p1)|(p2)|(p3)"
  </code></pre>
  
  <p>But they also do not work as expected. What is the correct to combine them?</p>
  
  <h3>Test cases:</h3>
  
  <ul>
  <li>"Likes": <code>ABC</code>, <code>ABCD</code>, <code>A</code>, <code>ABCBA</code></li>
  <li>"Dislikes": <code>ABBC</code> (pattern2), <code>THETXH</code>(pattern3), <code>ABACADA</code>(pattern3), <code>AbCD</code>(pattern1)</li>
  </ul>