Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/madisonmay/CommonRegex
A collection of common regular expressions bundled with an easy to use interface.
https://github.com/madisonmay/CommonRegex
Last synced: 12 days ago
JSON representation
A collection of common regular expressions bundled with an easy to use interface.
- Host: GitHub
- URL: https://github.com/madisonmay/CommonRegex
- Owner: madisonmay
- License: mit
- Created: 2013-12-17T08:43:14.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2023-04-20T18:31:08.000Z (over 1 year ago)
- Last Synced: 2024-05-10T15:20:53.693Z (6 months ago)
- Language: Python
- Homepage:
- Size: 111 KB
- Stars: 1,564
- Watchers: 40
- Forks: 141
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-projects - CommonRegex - A collection of common regular expressions bundled with an easy to use interface. (Python)
- awesome-discoveries - CommonRegex - a collection of common regular expressions bundled with an easy to use interface _(`Python`)_ (Libraries)
README
CommonRegex
===========Find all times, dates, links, phone numbers, emails, ip addresses, prices, hex colors, and credit card numbers in a string.
We did the hard work so you don't have to.Pull requests welcome!
Installation
-------
Install via pipsudo pip install commonregex
or via setup.pypython setup.py install
Usage
------```python
>>> 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 [email protected]""")
>>> 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
['[email protected]']
```
Alternatively, you can generate a single CommonRegex instance and use it to parse multiple segments of text.```python
>>> parser = CommonRegex()
>>> parser.times("When are you free? Do you want to meet up for coffee at 4:00?")
['4:00']
```
Finally, all regular expressions used are publicly exposed.```python
>>> from commonregex import email
>>> import re
>>> text = "...get in touch with my associate at [email protected]"
>>> re.sub(email, "[email protected]", text)
'...get in touch with my associate at [email protected]'
``````python
>>> 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
```
Please note that this module is currently English/US specific.Supported Methods/Attributes
------------------------------ `obj.dates`, `obj.dates()`
- `obj.times`, `obj.times()`
- `obj.phones`, `obj.phones()`
- `obj.phones_with_exts`, `obj.phones_with_exts()`
- `obj.links`, `obj.links()`
- `obj.emails`, `obj.emails()`
- `obj.ips`, `obj.ips()`
- `obj.ipv6s`, `obj.ipv6s()`
- `obj.prices`, `obj.prices()`
- `obj.hex_colors`, `obj.hex_colors()`
- `obj.credit_cards`, `obj.credit_cards()`
- `obj.btc_addresses`, `obj.btc_addresses()`
- `obj.street_addresses`, `obj.street_addresses()`
- `obj.zip_codes`, `obj.zip_codes()`
- `obj.po_boxes`, `obj.po_boxes()`
- `obj.ssn_number`, `obj.ssn_number()`CommonRegex Ports:
----------------------------------------
[CommonRegexRust](https://github.com/hskang9/CommonRegexRust)[CommonRegexJS] (https://github.com/talyssonoc/CommonRegexJS)
[CommonRegexScala] (https://github.com/everpeace/CommonRegexScala)
[CommonRegexJava] (https://github.com/talyssonoc/CommonRegexJava)
[CommonRegexCobra] (https://github.com/PurityLake/CommonRegex-Cobra)
[CommonRegexDart] (https://github.com/aufdemrand/CommonRegexDart)
[CommonRegexRuby] (https://github.com/talyssonoc/CommonRegexRuby)
[CommonRegexPHP] (https://github.com/james2doyle/CommonRegexPHP)
[![Analytics](https://ga-beacon.appspot.com/UA-46923950-1/CommonRegex/readme?pixel)](https://github.com/igrigorik/ga-beacon)