Title: Match US and UK Spellings
Slug: match_us_uk_spellings
Summary: Match US and UK Spellings
Date: 2016-05-01 12:00
Category: Regex
Tags: Basics
Authors: Chris Albon

Source: Regular Expressions Cookbook

Preliminaries


In [2]:
# Load regex package
import re

Create some text


In [3]:
# Create a variable containing a text string
text = 'It\s center and not centre.'

Apply regex


In [8]:
# Find any ISBN-10 or ISBN-13 number
re.findall(r'\bcent(?:er|re)\b', text)


Out[8]:
['center', 'centre']