├── .gitignore ├── MANIFEST ├── dist ├── commonregex-1.1.tar.gz ├── commonregex-1.2.tar.gz ├── commonregex-1.3.tar.gz ├── commonregex-1.4.tar.gz ├── commonregex-1.4.1.tar.gz ├── commonregex-1.4.2.tar.gz ├── commonregex-1.5.1.tar.gz ├── commonregex-1.5.2.tar.gz ├── commonregex-1.5.3.tar.gz ├── commonregex-1.5.4.tar.gz └── commonregex-1.5.5.tar.gz ├── setup.py ├── LICENSE ├── README.md ├── commonregex.py └── test.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc -------------------------------------------------------------------------------- /MANIFEST: -------------------------------------------------------------------------------- 1 | # file GENERATED by distutils, do NOT edit 2 | commonregex.py 3 | setup.py 4 | -------------------------------------------------------------------------------- /dist/commonregex-1.1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madisonmay/CommonRegex/HEAD/dist/commonregex-1.1.tar.gz -------------------------------------------------------------------------------- /dist/commonregex-1.2.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madisonmay/CommonRegex/HEAD/dist/commonregex-1.2.tar.gz -------------------------------------------------------------------------------- /dist/commonregex-1.3.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madisonmay/CommonRegex/HEAD/dist/commonregex-1.3.tar.gz -------------------------------------------------------------------------------- /dist/commonregex-1.4.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madisonmay/CommonRegex/HEAD/dist/commonregex-1.4.tar.gz -------------------------------------------------------------------------------- /dist/commonregex-1.4.1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madisonmay/CommonRegex/HEAD/dist/commonregex-1.4.1.tar.gz -------------------------------------------------------------------------------- /dist/commonregex-1.4.2.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madisonmay/CommonRegex/HEAD/dist/commonregex-1.4.2.tar.gz -------------------------------------------------------------------------------- /dist/commonregex-1.5.1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madisonmay/CommonRegex/HEAD/dist/commonregex-1.5.1.tar.gz -------------------------------------------------------------------------------- /dist/commonregex-1.5.2.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madisonmay/CommonRegex/HEAD/dist/commonregex-1.5.2.tar.gz -------------------------------------------------------------------------------- /dist/commonregex-1.5.3.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madisonmay/CommonRegex/HEAD/dist/commonregex-1.5.3.tar.gz -------------------------------------------------------------------------------- /dist/commonregex-1.5.4.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madisonmay/CommonRegex/HEAD/dist/commonregex-1.5.4.tar.gz -------------------------------------------------------------------------------- /dist/commonregex-1.5.5.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madisonmay/CommonRegex/HEAD/dist/commonregex-1.5.5.tar.gz -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | setup(name='commonregex', 3 | version='1.5.5', 4 | py_modules=['commonregex']) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Madison May 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CommonRegex 2 | =========== 3 | 4 | Find all times, dates, links, phone numbers, emails, ip addresses, prices, hex colors, and credit card numbers in a string. 5 | We did the hard work so you don't have to. 6 | 7 | Pull requests welcome! 8 | 9 | Installation 10 | ------- 11 | Install via pip 12 | 13 | sudo pip install commonregex 14 | 15 | or via setup.py 16 | 17 | python setup.py install 18 | 19 | 20 | Usage 21 | ------ 22 | 23 | ```python 24 | >>> from commonregex import CommonRegex 25 | >>> parsed_text = CommonRegex("""John, please get that article on www.linkedin.com to me by 5:00PM 26 | on Jan 9th 2012. 4:00 would be ideal, actually. If you have any 27 | questions, You can reach me at (519)-236-2723x341 or get in touch with 28 | my associate at harold.smith@gmail.com""") 29 | >>> parsed_text.times 30 | ['5:00PM', '4:00'] 31 | >>> parsed_text.dates 32 | ['Jan 9th 2012'] 33 | >>> parsed_text.links 34 | ['www.linkedin.com'] 35 | >>> parsed_text.phones 36 | ['(519)-236-2727'] 37 | >>> parsed_text.phones_with_exts 38 | ['(519)-236-2723x341'] 39 | >>> parsed_text.emails 40 | ['harold.smith@gmail.com'] 41 | ``` 42 | 43 | Alternatively, you can generate a single CommonRegex instance and use it to parse multiple segments of text. 44 | 45 | ```python 46 | >>> parser = CommonRegex() 47 | >>> parser.times("When are you free? Do you want to meet up for coffee at 4:00?") 48 | ['4:00'] 49 | ``` 50 | 51 | Finally, all regular expressions used are publicly exposed. 52 | 53 | ```python 54 | >>> from commonregex import email 55 | >>> import re 56 | >>> text = "...get in touch with my associate at harold.smith@gmail.com" 57 | >>> re.sub(email, "anon@example.com", text) 58 | '...get in touch with my associate at anon@example.com' 59 | ``` 60 | 61 | ```python 62 | >>> from commonregex import time 63 | >>> for m in time.finditer("Does 6:00 or 7:00 work better?"): 64 | >>> print m.start(), m.group() 65 | 5 6:00 66 | 13 7:00 67 | ``` 68 | 69 | 70 | Please note that this module is currently English/US specific. 71 | 72 | Supported Methods/Attributes 73 | ----------------------------- 74 | 75 | - `obj.dates`, `obj.dates()` 76 | - `obj.times`, `obj.times()` 77 | - `obj.phones`, `obj.phones()` 78 | - `obj.phones_with_exts`, `obj.phones_with_exts()` 79 | - `obj.links`, `obj.links()` 80 | - `obj.emails`, `obj.emails()` 81 | - `obj.ips`, `obj.ips()` 82 | - `obj.ipv6s`, `obj.ipv6s()` 83 | - `obj.prices`, `obj.prices()` 84 | - `obj.hex_colors`, `obj.hex_colors()` 85 | - `obj.credit_cards`, `obj.credit_cards()` 86 | - `obj.btc_addresses`, `obj.btc_addresses()` 87 | - `obj.street_addresses`, `obj.street_addresses()` 88 | - `obj.zip_codes`, `obj.zip_codes()` 89 | - `obj.po_boxes`, `obj.po_boxes()` 90 | - `obj.ssn_number`, `obj.ssn_number()` 91 | 92 | CommonRegex Ports: 93 | ---------------------------------------- 94 | [CommonRegexRust](https://github.com/hskang9/CommonRegexRust) 95 | 96 | [CommonRegexJS] (https://github.com/talyssonoc/CommonRegexJS) 97 | 98 | [CommonRegexScala] (https://github.com/everpeace/CommonRegexScala) 99 | 100 | [CommonRegexJava] (https://github.com/talyssonoc/CommonRegexJava) 101 | 102 | [CommonRegexCobra] (https://github.com/PurityLake/CommonRegex-Cobra) 103 | 104 | [CommonRegexDart] (https://github.com/aufdemrand/CommonRegexDart) 105 | 106 | [CommonRegexRuby] (https://github.com/talyssonoc/CommonRegexRuby) 107 | 108 | [CommonRegexPHP] (https://github.com/james2doyle/CommonRegexPHP) 109 | 110 | [![Analytics](https://ga-beacon.appspot.com/UA-46923950-1/CommonRegex/readme?pixel)](https://github.com/igrigorik/ga-beacon) 111 | 112 | -------------------------------------------------------------------------------- /commonregex.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | from types import MethodType 3 | import re 4 | 5 | date = re.compile('(?:(?]+[^\s`!()\[\]{};:\'".,<>?\xab\xbb\u201c\u201d\u2018\u2019])?)', re.IGNORECASE) 10 | email = re.compile("([a-z0-9!#$%&'*+\/=?^_`{|.}~-]+@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)", re.IGNORECASE) 11 | ip = re.compile('(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)', re.IGNORECASE) 12 | ipv6 = re.compile('\s*(?!.*::.*::)(?:(?!:)|:(?=:))(?:[0-9a-f]{0,4}(?:(?<=::)|(?