Advanced Regular Expression Patterns

For when your regex skills are so advanced, you're practically speaking fluent Python.


      # Find all words that start with 'e'
      import re
      words = ["hello", "world", "example"]
      pattern = r"^\w*e"
      print([w for w in words if re.match(pattern, w)])

      # Find all words that end with 'y'
      import re
      words = ["hello", "world", "example"]
      pattern = r"\w*y$"
      print([w for w in words if re.match(pattern, w)])

      # Find all words that have 'a' in them
      import re
      words = ["hello", "world", "example"]
      pattern = r"\w*a\w"
      print([w for w in words if re.match(pattern, w)])
    

When the going gets tough, the tough get regex.