Title: Match ZIP Codes
Slug: match_zip_codes
Summary: Match ZIP Codes
Date: 2016-05-01 12:00
Category: Regex
Tags: Basics
Authors: Chris Albon
Source: Regular Expressions Cookbook
In [3]:
# Load regex package
import re
In [14]:
# Create a variable containing a text string
text = '3829 South Ave Street, Pheonix, AZ 34923'
In [15]:
# Find any ISBN-10 or ISBN-13 number
re.findall(r'[0-9]{5}(?:-[0-9]{4})?', text)
Out[15]: