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.
pip install commonregexVerified import paths — ran on the pinned version, not inferred.
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.
Review the source code's regex patterns (`commonregex.py`) if you need to adapt them for non-English or non-US specific text, or consider alternative libraries.
For performance-critical applications, consider using 'commonregex-improved' (PyPI: `crim`) or manually compiling and reusing `re` patterns from `commonregex` if specific patterns are needed.
When using the raw regex patterns (e.g., `from commonregex import ip`), ensure you validate the results against your specific requirements or add word boundaries (e.g., `\b`) to the patterns if not already present, for stricter matching.
Access the extracted data as an attribute, e.g., `parsed_text.dates`. If you want to process *new* text with an existing `CommonRegex` instance, you would use methods like `parser.dates('new text here')`.To import the main parsing class, use `from commonregex import CommonRegex`. To import individual regex patterns, use `from commonregex import date` (or `email`, `time`, etc.).
This library is not suitable for non-English or non-US specific content without significant modification of its internal regex patterns. Consider using a library designed for internationalization or writing custom regexes for your target language/locale.
No dependency data recorded yet.