Title: Match Any Of A Series Of Options
Slug: match_any_of_series_of_characters
Summary: Match Any Of A Series Of Options
Date: 2016-05-01 12:00
Category: Regex
Tags: Basics
Authors: Chris Albon

Based on: Regular Expressions Cookbook

Preliminaries


In [1]:
# Load regex package
import re

Create some text


In [2]:
# Create a variable containing a text string
text = 'The quick brown fox jumped over the lazy brown bear.'

Apply regex


In [3]:
# Find any of fox, snake, or bear
re.findall(r'fox|snake|bear', text)


Out[3]:
['fox', 'bear']