v Match US and UK Spellings - Regex

Match US and UK Spellings

Source: Regular Expressions Cookbook

Preliminaries

# Load regex package
import re

Create some text

# Create a variable containing a text string
text = 'It\s center and not centre.'

Apply regex

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