# Regexa - Python Regex Utility Library
Regexa is a comprehensive Python library that simplifies working with regular expressions for common text processing tasks. It provides an easy-to-use interface for validations, extractions, and text processing operations.
## Features
- Email, phone number and URL validation
- Password strength validation with detailed feedback
- Text extraction (emails, phones, URLs, hashtags, mentions etc)
- Date extraction in multiple formats
- File path processing
- Network validations (IP address, MAC address)
- Credit card validation
- Text cleaning utilities
- Pattern matching and counting
## Installation
```bash
pip install regexa
```
# Basic Usage
## Initialization
```python
from regexa import Regexa
rx = Regexa()
```
## 1. Email validation
```python
email = "john.doe@example.com"
print(f"Is email valid? {rx.match_email(email)}")
# Result: Is email valid? True
# Comment: The email is valid as it follows the standard email format
```
## 2. Password strength check
```python
password = "MyStr0ng#Pass"
strength = rx.validate_password_strength(password)
print(f"Password strength: {strength['strength']}")
print(f"Password feedback: {strength['feedback']}")
# Result:
# Password strength: Excellent
# Password feedback: ['Password length sufficient', 'Has uppercase letters', 'Has lowercase letters', 'Has numbers', 'Has special characters']
# Comment: The password is excellent because it meets all criteria: length, uppercase, lowercase, numbers, and special characters
```
## 3. Extract all data from text
```python
text = """
Contact me at john.doe@example.com or call +6281234567890
Visit our website: https://example.com
Follow us @company #tech #python
Meeting on 25/12/2023 and 2023-12-31
Credit card: 4111111111111111
"""
extracted = rx.extract_all(text)
print("\nExtracted data:")
for key, value in extracted.items():
print(f"{key}: {value}")
# Result:
# emails: ['john.doe@example.com']
# phones: ['+6281234567890']
# urls: ['https://example.com']
# hashtags: ['#tech', '#python']
# mentions: ['@company']
# numbers: ['6281234567890', '25', '12', '2023', '2023', '12', '31']
# words: ['Contact', 'me', 'at', 'john', 'doe', 'example', 'com', ...]
# Comment: Successfully extracted all different types of data from the text
```
## 4. Date extraction
```python
dates = rx.extract_dates(text)
print("\nFound dates:")
for date in dates:
print(f"Date: {date['date']} (Format: {date['format']})")
# Result:
# Date: 25/12/2023 (Format: dd/mm/yyyy)
# Date: 2023-12-31 (Format: yyyy-mm-dd)
# Comment: Detected dates in different formats
```
## 5. URL validation
```python
url = "https://example.com"
print(f"\nIs URL valid? {rx.match_url(url)}")
# Result: Is URL valid? True
# Comment: URL is valid as it contains the correct protocol and domain format
```
## 6. Credit card validation
```python
card_number = "4111111111111111"
card_validation = rx.validate_credit_card(card_number)
print(f"\nCredit card validation: {card_validation}")
# Result: Credit card validation: {'is_valid': True, 'card_type': 'visa', 'number': '4111111111111111'}
# Comment: Detected as a valid Visa card number
```
## 7. Clean text
```python
cleaned_text = rx.clean_text("Hello, World! @#$%")
print(f"\nCleaned text: {cleaned_text}")
# Result: Cleaned text: Hello World
# Comment: Removed all special characters, leaving only alphanumeric characters and spaces
```
## 8. IP validation
```python
ip = "192.168.1.1"
ip_validation = rx.validate_ip(ip)
print(f"\nIP validation: {ip_validation}")
# Result: IP validation: {'is_valid': True, 'type': 'IPv4', 'private': True}
# Comment: Valid IPv4 address identified as a private IP address
```
# Documentation
## Email Validation
```python
rx.match_email(text: str) -> bool
```
Validates if a string is a properly formatted email address.
## Phone Number Validation
```python
rx.match_phone_id(text: str) -> bool
```
Validates Indonesian phone numbers.
## URL Validation
```python
rx.match_url(text: str) -> bool
```
Checks if a string is a valid URL with HTTP/HTTPS protocol.
## Password Validation
```python
rx.validate_password_strength(password: str) -> Dict[str, Any]
```
Validates password strength and provides detailed feedback:
- Score (0-5)
- Strength level
- Specific feedback
- Overall validity
## Text Extraction
```python
rx.extract_all(text: str) -> Dict[str, List[str]]
```
Extracts various elements from text:
- Email addresses
- Phone numbers
- URLs
- Hashtags
- @mentions
- Numbers
- Words
## Text Cleaning
```python
rx.clean_text(text: str, remove_spaces: bool = False) -> str
```
Cleans text by removing special characters. Optional space removal.
## Date Extraction
```python
rx.extract_dates(text: str) -> List[Dict[str, Any]]
```
Extracts dates in various formats:
- dd/mm/yyyy
- yyyy-mm-dd
- dd-mm-yyyy
- Natural format (e.g. "25 December 2023")
## File Path Processing
```python
rx.extract_filename(path: str) -> Dict[str, str]
```
Extracts components from file paths:
- Directory
- Filename
- Extension
- Full path
## IP Address Validation
```python
rx.validate_ip(ip: str) -> Dict[str, Any]
```
Validates IPv4 and IPv6 addresses and provides:
- Validity status
- IP version
- Private network status (IPv4)
## Pattern Matching
```python
rx.count_matches(text: str, pattern: str) -> Dict[str, Any]
```
Counts pattern matches in text and provides:
- Match count
- Match positions
- Used pattern
## Credit Card Validation
```python
rx.validate_credit_card(number: str) -> Dict[str, Any]
```
Validates credit card numbers and identifies card type:
- Visa
- Mastercard
- American Express
- Discover
# Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
# License
This project is licensed under the MIT License - see the LICENSE file for details.
Raw data
{
"_id": null,
"home_page": "https://github.com/bri-anadi/regexa",
"name": "regexa",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "regex, regular expressions, text processing, validation",
"author": "Brian Adi",
"author_email": "uix.brianadi@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/0c/fd/5f7eeaf28b5d5e300199ae141d505257ea01f327c3a5ad425b5f03e9b339/regexa-0.1.1.tar.gz",
"platform": null,
"description": "# Regexa - Python Regex Utility Library\n\nRegexa is a comprehensive Python library that simplifies working with regular expressions for common text processing tasks. It provides an easy-to-use interface for validations, extractions, and text processing operations.\n\n## Features\n\n- Email, phone number and URL validation\n- Password strength validation with detailed feedback\n- Text extraction (emails, phones, URLs, hashtags, mentions etc)\n- Date extraction in multiple formats\n- File path processing\n- Network validations (IP address, MAC address)\n- Credit card validation\n- Text cleaning utilities\n- Pattern matching and counting\n\n## Installation\n\n```bash\npip install regexa\n```\n\n# Basic Usage\n## Initialization\n```python\nfrom regexa import Regexa\n\nrx = Regexa()\n```\n\n## 1. Email validation\n```python\nemail = \"john.doe@example.com\"\nprint(f\"Is email valid? {rx.match_email(email)}\")\n\n# Result: Is email valid? True\n# Comment: The email is valid as it follows the standard email format\n```\n\n## 2. Password strength check\n```python\npassword = \"MyStr0ng#Pass\"\nstrength = rx.validate_password_strength(password)\nprint(f\"Password strength: {strength['strength']}\")\nprint(f\"Password feedback: {strength['feedback']}\")\n\n# Result:\n# Password strength: Excellent\n# Password feedback: ['Password length sufficient', 'Has uppercase letters', 'Has lowercase letters', 'Has numbers', 'Has special characters']\n# Comment: The password is excellent because it meets all criteria: length, uppercase, lowercase, numbers, and special characters\n```\n\n## 3. Extract all data from text\n```python\ntext = \"\"\"\nContact me at john.doe@example.com or call +6281234567890\nVisit our website: https://example.com\nFollow us @company #tech #python\nMeeting on 25/12/2023 and 2023-12-31\nCredit card: 4111111111111111\n\"\"\"\n\nextracted = rx.extract_all(text)\nprint(\"\\nExtracted data:\")\nfor key, value in extracted.items():\n print(f\"{key}: {value}\")\n\n# Result:\n# emails: ['john.doe@example.com']\n# phones: ['+6281234567890']\n# urls: ['https://example.com']\n# hashtags: ['#tech', '#python']\n# mentions: ['@company']\n# numbers: ['6281234567890', '25', '12', '2023', '2023', '12', '31']\n# words: ['Contact', 'me', 'at', 'john', 'doe', 'example', 'com', ...]\n# Comment: Successfully extracted all different types of data from the text\n```\n\n## 4. Date extraction\n```python\ndates = rx.extract_dates(text)\nprint(\"\\nFound dates:\")\nfor date in dates:\n print(f\"Date: {date['date']} (Format: {date['format']})\")\n\n# Result:\n# Date: 25/12/2023 (Format: dd/mm/yyyy)\n# Date: 2023-12-31 (Format: yyyy-mm-dd)\n# Comment: Detected dates in different formats\n```\n\n## 5. URL validation\n```python\nurl = \"https://example.com\"\nprint(f\"\\nIs URL valid? {rx.match_url(url)}\")\n\n# Result: Is URL valid? True\n# Comment: URL is valid as it contains the correct protocol and domain format\n```\n\n## 6. Credit card validation\n```python\ncard_number = \"4111111111111111\"\ncard_validation = rx.validate_credit_card(card_number)\nprint(f\"\\nCredit card validation: {card_validation}\")\n\n# Result: Credit card validation: {'is_valid': True, 'card_type': 'visa', 'number': '4111111111111111'}\n# Comment: Detected as a valid Visa card number\n```\n\n## 7. Clean text\n```python\ncleaned_text = rx.clean_text(\"Hello, World! @#$%\")\nprint(f\"\\nCleaned text: {cleaned_text}\")\n\n# Result: Cleaned text: Hello World\n# Comment: Removed all special characters, leaving only alphanumeric characters and spaces\n```\n\n## 8. IP validation\n```python\nip = \"192.168.1.1\"\nip_validation = rx.validate_ip(ip)\nprint(f\"\\nIP validation: {ip_validation}\")\n\n# Result: IP validation: {'is_valid': True, 'type': 'IPv4', 'private': True}\n# Comment: Valid IPv4 address identified as a private IP address\n```\n\n# Documentation\n## Email Validation\n```python\nrx.match_email(text: str) -> bool\n```\nValidates if a string is a properly formatted email address.\n\n## Phone Number Validation\n```python\nrx.match_phone_id(text: str) -> bool\n```\nValidates Indonesian phone numbers.\n\n## URL Validation\n```python\nrx.match_url(text: str) -> bool\n```\nChecks if a string is a valid URL with HTTP/HTTPS protocol.\n\n## Password Validation\n```python\nrx.validate_password_strength(password: str) -> Dict[str, Any]\n```\nValidates password strength and provides detailed feedback:\n\n- Score (0-5)\n- Strength level\n- Specific feedback\n- Overall validity\n\n## Text Extraction\n```python\nrx.extract_all(text: str) -> Dict[str, List[str]]\n```\nExtracts various elements from text:\n\n- Email addresses\n- Phone numbers\n- URLs\n- Hashtags\n- @mentions\n- Numbers\n- Words\n\n## Text Cleaning\n```python\nrx.clean_text(text: str, remove_spaces: bool = False) -> str\n```\nCleans text by removing special characters. Optional space removal.\n\n## Date Extraction\n```python\nrx.extract_dates(text: str) -> List[Dict[str, Any]]\n```\nExtracts dates in various formats:\n\n- dd/mm/yyyy\n- yyyy-mm-dd\n- dd-mm-yyyy\n- Natural format (e.g. \"25 December 2023\")\n\n## File Path Processing\n```python\nrx.extract_filename(path: str) -> Dict[str, str]\n```\nExtracts components from file paths:\n\n- Directory\n- Filename\n- Extension\n- Full path\n\n## IP Address Validation\n```python\nrx.validate_ip(ip: str) -> Dict[str, Any]\n```\nValidates IPv4 and IPv6 addresses and provides:\n\n- Validity status\n- IP version\n- Private network status (IPv4)\n\n## Pattern Matching\n```python\nrx.count_matches(text: str, pattern: str) -> Dict[str, Any]\n```\nCounts pattern matches in text and provides:\n\n- Match count\n- Match positions\n- Used pattern\n\n## Credit Card Validation\n```python\nrx.validate_credit_card(number: str) -> Dict[str, Any]\n```\nValidates credit card numbers and identifies card type:\n\n- Visa\n- Mastercard\n- American Express\n- Discover\n\n# Contributing\nContributions are welcome! Please feel free to submit a Pull Request.\n\n# License\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n\n",
"bugtrack_url": null,
"license": null,
"summary": "A modern, full-featured regex library for Python",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/bri-anadi/regexa"
},
"split_keywords": [
"regex",
" regular expressions",
" text processing",
" validation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "46d5ab459cd78e85fd3baf53cc417b0408097c4ef76eade63130f46a774cc491",
"md5": "8716bd75e458945b453e7e0b26d8a2b3",
"sha256": "f55f28c9f81bab7ad8357ba125b57ea33b4e44cde2cfd9fae6dfeab9261ae375"
},
"downloads": -1,
"filename": "regexa-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8716bd75e458945b453e7e0b26d8a2b3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 7977,
"upload_time": "2024-11-30T01:01:27",
"upload_time_iso_8601": "2024-11-30T01:01:27.149799Z",
"url": "https://files.pythonhosted.org/packages/46/d5/ab459cd78e85fd3baf53cc417b0408097c4ef76eade63130f46a774cc491/regexa-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0cfd5f7eeaf28b5d5e300199ae141d505257ea01f327c3a5ad425b5f03e9b339",
"md5": "df29fb48aa46d961cb2a4f178d62fe64",
"sha256": "081bbb8bc4d85c167e8782a9548a6be6ba5fa0bf742a38b6a9708b2158a9d4d0"
},
"downloads": -1,
"filename": "regexa-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "df29fb48aa46d961cb2a4f178d62fe64",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 9095,
"upload_time": "2024-11-30T01:01:35",
"upload_time_iso_8601": "2024-11-30T01:01:35.590248Z",
"url": "https://files.pythonhosted.org/packages/0c/fd/5f7eeaf28b5d5e300199ae141d505257ea01f327c3a5ad425b5f03e9b339/regexa-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-30 01:01:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "bri-anadi",
"github_project": "regexa",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "regexa"
}