fork(1) download
  1. import re
  2. colors=['red','gray','black','white','brown']
  3. animals=['fox','bear','hare','squirrel','wolf']
  4. pattern = fr"(?i)\b(?:{'|'.join(colors)})\s+(?:{'|'.join(animals)})\b"
  5. doc_string = "Hello, red fox! Hello Black Hare! What's up whItE sQuirrel, brown wolf and gray bear!"
  6. print ( re.findall(pattern, doc_string) )
Success #stdin #stdout 0.02s 9512KB
stdin
Standard input is empty
stdout
['red fox', 'Black Hare', 'whItE sQuirrel', 'brown wolf', 'gray bear']