Install CommonRegex via pip or setup.py
masterYou can install CommonRegex using pip or by using the setup.py file directly.
sudo pip install commonregexOr via setup.py
python setup.py installrepository·master·Indexed 23 days ago
https://github.com/madisonmay/commonregexA Python library for extracting common data patterns such as emails, phone numbers, dates, and IPs from strings using pre-configured regular expressions. It provides a CommonRegex class for multi-pattern extraction and individual regex modules for specific data types.
You can install CommonRegex using pip or by using the setup.py file directly.
sudo pip install commonregexpython setup.py installInstead of passing text to the constructor every time, you can create a single CommonRegex instance and call specific extraction methods on different strings of text.
>>> parser = CommonRegex()
>>> parser.times("When are you free? Do you want to meet up for coffee at 4:00?")
['4:00']CommonRegex exposes its underlying regular expressions as individual modules (e.g., email, time). You can use these directly with Python's re module for tasks like substitution or finding iterators.
>>> from commonregex import email
>>> import re
>>> text = "...get in touch with my associate at harold.smith@gmail.com"
>>> re.sub(email, "anon@example.com", text)
'...get in touch with my associate at anon@example.com'>>> from commonregex import time
>>> for m in time.finditer("Does 6:00 or 7:00 work better?"):
>>> print m.start(), m.group()
5 6:00
13 7:00 To extract multiple types of information from a single string, instantiate the CommonRegex class with your text. You can then access specific data types via attributes like .times, .dates, .links, .phones, .phones_with_exts, and .emails.
>>> from commonregex import CommonRegex
>>> parsed_text = CommonRegex("""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""")
>>> parsed_text.times
['5:00PM', '4:00']
>>> parsed_text.dates
['Jan 9th 2012']
>>> parsed_text.links
['www.linkedin.com']
>>> parsed_text.phones
['(519)-236-2727']
>>> parsed_text.phones_with_exts
['(519)-236-2723x341']
>>> parsed_text.emails
['harold.smith@gmail.com']CommonRegex object, the following attributes (or methods) are available to extract specific data types. Note that this module is currently English/US specific.