CommonRegex

1.5.4 · maintenance · verified Thu Apr 16

CommonRegex is a Python library that bundles a collection of commonly used regular expressions with a straightforward API. It simplifies the extraction of various patterns like dates, times, emails, phone numbers, links, IP addresses, prices, and street addresses from text strings. The current version is 1.5.4, released in 2014, indicating a maintenance-only cadence without active development.

Common errors

Warnings

Install

Imports

Quickstart

Instantiate the `CommonRegex` class with the text to be parsed. Extracted patterns can then be accessed as attributes (e.g., `parsed_text.dates`). For new texts, you can either create a new instance or call the corresponding method on an existing instance.

from commonregex import CommonRegex

text = """John, please get that article on www.linkedin.com to me by 5:00PM on Jan 9th 2012.
4:00 would be ideal, actually. If you have any questions, You can reach me at (519)-236-2723x341
or get in touch with my associate at harold.smith@gmail.com. Check my IP 192.168.1.1."""

# Instantiate CommonRegex with the text
parsed_text = CommonRegex(text)

# Access extracted data via attributes
print(f"Dates: {parsed_text.dates}")
print(f"Times: {parsed_text.times}")
print(f"Links: {parsed_text.links}")
print(f"Phones with Exts: {parsed_text.phones_with_exts}")
print(f"Emails: {parsed_text.emails}")
print(f"IPs: {parsed_text.ips}")

# Alternatively, use a single instance for multiple texts
parser = CommonRegex()
print(f"Later time: {parser.times('Meet me at 7:30 AM.')}")

view raw JSON →