### Phone Number Extraction Examples Source: https://context7.com/madisonmay/commonregex/llms.txt Extracts phone numbers in various standard and international formats. Use `phones_with_exts` to include extensions. ```python from commonregex import CommonRegex parser = CommonRegex() # Standard phone formats print(parser.phones("1234567890")) # ['1234567890'] print(parser.phones("+1 234 567 8900")) # ['+1 234 567 8900'] print(parser.phones("234-567-8900")) # ['234-567-8900'] print(parser.phones("1-234-567-8900")) # ['1-234-567-8900'] print(parser.phones("1.234.567.8900")) # ['1.234.567.8900'] print(parser.phones("(123) 456 7890")) # ['(123) 456 7890'] print(parser.phones("+41 22 730 5989")) # ['+41 22 730 5989'] print(parser.phones("(+41) 22 730 5989")) # ['(+41) 22 730 5989'] # Phones with extensions print(parser.phones_with_exts("(523)222-8888 ext 527")) # ['(523)222-8888 ext 527'] print(parser.phones_with_exts("(523)222-8888x623")) # ['(523)222-8888x623'] print(parser.phones_with_exts("523-222-8888EXT623")) # ['523-222-8888EXT623'] print(parser.phones_with_exts("(523) 222-8888 x 623")) # ['(523) 222-8888 x 623'] ``` -------------------------------- ### Date Extraction Examples Source: https://context7.com/madisonmay/commonregex/llms.txt Extracts dates in various numeric and verbose formats. Ensure the correct parser method is used for the desired format. ```python from commonregex import CommonRegex parser = CommonRegex() # Numeric formats print(parser.dates("1-19-14")) # ['1-19-14'] print(parser.dates("1.19.14")) # ['1.19.14'] print(parser.dates("01/19/2014")) # ['01/19/2014'] # Verbose formats print(parser.dates("January 19th, 2014")) # ['January 19th, 2014'] print(parser.dates("Jan. 19th, 2014")) # ['Jan. 19th, 2014'] print(parser.dates("Jan 19 2014")) # ['Jan 19 2014'] print(parser.dates("19 Jan 2014")) # ['19 Jan 2014'] ``` -------------------------------- ### Time Extraction Examples Source: https://context7.com/madisonmay/commonregex/llms.txt Extracts times in 12-hour and 24-hour formats, with or without AM/PM indicators. Handles multiple times within a single text segment. ```python from commonregex import CommonRegex parser = CommonRegex() print(parser.times("09:45")) # ['09:45'] print(parser.times("9:45")) # ['9:45'] print(parser.times("23:45")) # ['23:45'] print(parser.times("9:00am")) # ['9:00am'] print(parser.times("9am")) # ['9am'] print(parser.times("9:00 A.M.")) # ['9:00 A.M.'] print(parser.times("9:00 pm")) # ['9:00 pm'] # Multiple times print(parser.times("Call between 9:00am and 5:00pm")) # ['9:00am', '5:00pm'] ``` -------------------------------- ### Extract Bitcoin Addresses Source: https://context7.com/madisonmay/commonregex/llms.txt Extracts Bitcoin wallet addresses in Base58 format, starting with '1' or '3'. Ensure the CommonRegex library is imported. ```python from commonregex import CommonRegex parser = CommonRegex() print(parser.btc_addresses("1LgqButDNV2rVHe9DATt6WqD8tKZEKvaK2")) # ['1LgqButDNV2rVHe9DATt6WqD8tKZEKvaK2'] print(parser.btc_addresses("19P6EYhu6kZzRy9Au4wRRZVE8RemrxPbZP")) # ['19P6EYhu6kZzRy9Au4wRRZVE8RemrxPbZP'] print(parser.btc_addresses("1Bow5EMqtDGV5n5xZVgdpRPJiiDK6XSjiC")) # ['1Bow5EMqtDGV5n5xZVgdpRPJiiDK6XSjiC'] ``` -------------------------------- ### Iterate Through Time Matches with CommonRegex Source: https://github.com/madisonmay/commonregex/blob/master/README.md Use the 'time' regex from CommonRegex with 'finditer' to locate and extract all time occurrences within a string, printing their start index and matched value. ```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 ``` -------------------------------- ### Direct Regex Access for Substitution and Matching Source: https://context7.com/madisonmay/commonregex/llms.txt Access exported regex patterns for direct use with Python's `re` module for custom operations like substitution, finding matches with positions, and validation. ```python from commonregex import email, time, date, phone, link, ip import re # Substitution - anonymize emails text = "Contact harold.smith@gmail.com for details" anonymized = re.sub(email, "redacted@example.com", text) print(anonymized) # 'Contact redacted@example.com for details' ``` ```python # Find with positions using finditer text = "Does 6:00 or 7:00 work better?" for match in time.finditer(text): print(f"Position {match.start()}: {match.group()}") # Position 5: 6:00 # Position 13: 7:00 ``` ```python # Custom validation def is_valid_email(text): return bool(email.fullmatch(text)) print(is_valid_email("test@example.com")) # True (if fullmatch supported) ``` ```python # Compile with additional flags import re custom_date = re.compile(date.pattern, re.IGNORECASE | re.MULTILINE) ``` -------------------------------- ### Parse Specific Patterns with CommonRegex Instance Source: https://github.com/madisonmay/commonregex/blob/master/README.md Create a CommonRegex instance without initial text to parse individual strings for specific patterns like times. This is useful for processing multiple text segments. ```python >>> parser = CommonRegex() >>> parser.times("When are you free? Do you want to meet up for coffee at 4:00?") ['4:00'] ``` -------------------------------- ### Extract URLs and Links Source: https://context7.com/madisonmay/commonregex/llms.txt Extracts URLs and web links, including those with query parameters and subdomains. The CommonRegex library must be imported. ```python from commonregex import CommonRegex parser = CommonRegex() print(parser.links("www.google.com")) # ['www.google.com'] print(parser.links("http://www.google.com")) # ['http://www.google.com'] print(parser.links("www.google.com/?query=dog")) # ['www.google.com/?query=dog'] print(parser.links("sub.example.com")) # ['sub.example.com'] print(parser.links("http://www.google.com/%&#/?q=dog")) # ['http://www.google.com/%&#/?q=dog'] print(parser.links("google.com")) # ['google.com'] ``` -------------------------------- ### Parse Text with CommonRegex Source: https://github.com/madisonmay/commonregex/blob/master/README.md Instantiate CommonRegex with a string to extract multiple patterns like times, dates, links, and emails. Access extracted data via attributes. ```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 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'] ``` -------------------------------- ### Extract IP Addresses (IPv4 and IPv6) Source: https://context7.com/madisonmay/commonregex/llms.txt Extracts both IPv4 and IPv6 addresses from text. Ensure the CommonRegex library is imported. ```python from commonregex import CommonRegex parser = CommonRegex() # IPv4 addresses print(parser.ips("127.0.0.1")) # ['127.0.0.1'] print(parser.ips("192.168.1.1")) # ['192.168.1.1'] print(parser.ips("8.8.8.8")) # ['8.8.8.8'] # IPv6 addresses print(parser.ipv6s("fe80:0000:0000:0000:0204:61ff:fe9d:f156")) # ['fe80:0000:0000:0000:0204:61ff:fe9d:f156'] print(parser.ipv6s("fe80::204:61ff:fe9d:f156")) # ['fe80::204:61ff:fe9d:f156'] print(parser.ipv6s("::1")) # ['::1'] # Mixed format IPv6 print(parser.ipv6s("fe80::204:61ff:254.157.241.86")) # ['fe80::204:61ff:254.157.241.86'] ``` -------------------------------- ### CommonRegex Class: Text Pattern Extraction Source: https://context7.com/madisonmay/commonregex/llms.txt Instantiate CommonRegex with text to extract all supported patterns as attributes, or create a parser instance to process multiple text segments using method calls. ```python from commonregex import CommonRegex # Mode 1: Instantiate with text - results as attributes text = """Contact John at john.smith@gmail.com or call (519)-236-2723x341. Meeting scheduled for Jan 9th 2014 at 5:00PM at 101 Main Street. Payment: $1,250.00 to bitcoin address 1LgqButDNV2rVHe9DATt6WqD8tKZEKvaK2. Server IP: 192.168.1.1, website: www.example.com Color theme: #4e32ff, Card: 4111-1111-1111-1111""" parsed = CommonRegex(text) print(parsed.emails) # ['john.smith@gmail.com'] print(parsed.phones_with_exts) # ['(519)-236-2723x341'] print(parsed.dates) # ['Jan 9th 2014'] print(parsed.times) # ['5:00PM'] print(parsed.street_addresses) # ['101 Main Street'] print(parsed.prices) # ['$1,250.00'] print(parsed.btc_addresses) # ['1LgqButDNV2rVHe9DATt6WqD8tKZEKvaK2'] print(parsed.ips) # ['192.168.1.1'] print(parsed.links) # ['www.example.com'] print(parsed.hex_colors) # ['#4e32ff'] print(parsed.credit_cards) # ['4111-1111-1111-1111'] # Mode 2: Reusable parser for multiple texts parser = CommonRegex() print(parser.times("Meeting at 4:00pm or 5:30")) # ['4:00pm', '5:30'] print(parser.emails("Email me at test@example.com")) # ['test@example.com'] print(parser.dates("Due: 12/25/2024 or January 1st, 2025")) # ['12/25/2024', 'January 1st, 2025'] ``` -------------------------------- ### Extract SSN Numbers with CommonRegex Source: https://context7.com/madisonmay/commonregex/llms.txt Use the `ssn_number` method to extract US Social Security Numbers in standard formats. ```python from commonregex import CommonRegex parser = CommonRegex() print(parser.ssn_number("523 23 4566")) # ['523 23 4566'] print(parser.ssn_number("523-04-1234")) # ['523-04-1234'] ``` -------------------------------- ### Extract USD Prices Source: https://context7.com/madisonmay/commonregex/llms.txt Extracts USD prices, including those with dollar signs and comma-separated thousands. Requires importing the CommonRegex library. ```python from commonregex import CommonRegex parser = CommonRegex() print(parser.prices("$1.23")) # ['$1.23'] print(parser.prices("$1")) # ['$1'] print(parser.prices("$1,000")) # ['$1,000'] print(parser.prices("$10,000.00")) # ['$10,000.00'] # In context print(parser.prices("Total: $1,234.56 plus $99.99 shipping")) # ['$1,234.56', '$99.99'] ``` -------------------------------- ### Extract US Street Addresses, Zip Codes, and PO Boxes Source: https://context7.com/madisonmay/commonregex/llms.txt Extracts US street addresses, zip codes (5-digit and 9-digit), and PO Box numbers. Requires importing the CommonRegex library. ```python from commonregex import CommonRegex parser = CommonRegex() # Street addresses print(parser.street_addresses("101 main st.")) # ['101 main st'] print(parser.street_addresses("504 parkwood drive")) # ['504 parkwood drive'] print(parser.street_addresses("3 elm boulevard")) # ['3 elm boulevard'] print(parser.street_addresses("500 elm street")) # ['500 elm street'] # Zip codes print(parser.zip_codes("02540")) # ['02540'] print(parser.zip_codes("02540-4119")) # ['02540-4119'] # PO Boxes print(parser.po_boxes("PO Box 123456")) # ['PO Box 123456'] print(parser.po_boxes("p.o. box 234234")) # ['p.o. box 234234'] ``` -------------------------------- ### Use CommonRegex Email Pattern with re.sub Source: https://github.com/madisonmay/commonregex/blob/master/README.md Access the 'email' regex directly from CommonRegex and use it with Python's 're.sub' to replace email addresses in a string. ```python >>> 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' ``` -------------------------------- ### Extract Email Addresses Source: https://context7.com/madisonmay/commonregex/llms.txt Extracts various valid email formats from text. Ensure the CommonRegex library is imported. ```python from commonregex import CommonRegex parser = CommonRegex() print(parser.emails("john.smith@gmail.com")) # ['john.smith@gmail.com'] print(parser.emails("john_smith@gmail.com")) # ['john_smith@gmail.com'] print(parser.emails("john@example.net")) # ['john@example.net'] # Multiple emails in text text = "Contact support@company.com or sales@company.org for help" print(parser.emails(text)) # ['support@company.com', 'sales@company.org'] ``` -------------------------------- ### Extract Credit Card Numbers Source: https://context7.com/madisonmay/commonregex/llms.txt Extracts credit card numbers in various formats, including dashes, spaces, or continuous digits. Requires importing the CommonRegex library. ```python from commonregex import CommonRegex parser = CommonRegex() print(parser.credit_cards("0000-0000-0000-0000")) # ['0000-0000-0000-0000'] print(parser.credit_cards("0123456789012345")) # ['0123456789012345'] print(parser.credit_cards("0000 0000 0000 0000")) # ['0000 0000 0000 0000'] print(parser.credit_cards("012345678901234")) # ['012345678901234'] (15-digit Amex) ``` -------------------------------- ### Extract Hex Color Codes Source: https://context7.com/madisonmay/commonregex/llms.txt Extracts CSS hex color codes in 3, 6, or 8 character formats (with alpha). The CommonRegex library must be imported. ```python from commonregex import CommonRegex parser = CommonRegex() print(parser.hex_colors("#fff")) # ['#fff'] print(parser.hex_colors("#123")) # ['#123'] print(parser.hex_colors("#4e32ff")) # ['#4e32ff'] print(parser.hex_colors("#12345678")) # ['#12345678'] (with alpha) # In CSS context css = "body { color: #333; background: #f0f0f0; }" print(parser.hex_colors(css)) # ['#333', '#f0f0f0'] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.