fork download
  1. import re
  2.  
  3. stringToMatch = "sydney bogota berlin tokyo nairobi denver rio";
  4.  
  5. match = re.search(r'(\b(?!bcogo|nai)\w*\b)\w+', stringToMatch)
  6. print(match)
  7.  
  8. m = re.search(r'\w*\b\w+', stringToMatch)
  9. print(match)
Success #stdin #stdout 0.03s 9448KB
stdin
Standard input is empty
stdout
<re.Match object; span=(0, 6), match='sydney'>
<re.Match object; span=(0, 6), match='sydney'>