STRling 2.2.0__tar.gz → 2.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- strling-2.3.0/PKG-INFO +113 -0
- strling-2.3.0/README.md +108 -0
- strling-2.3.0/STRling/__init__.py +1 -0
- {strling-2.2.0 → strling-2.3.0}/STRling/simply/constructors.py +1 -1
- {strling-2.2.0 → strling-2.3.0}/STRling/simply/pattern.py +2 -2
- {strling-2.2.0 → strling-2.3.0}/STRling/simply/static.py +114 -1
- strling-2.3.0/STRling.egg-info/PKG-INFO +113 -0
- {strling-2.2.0 → strling-2.3.0}/STRling.egg-info/SOURCES.txt +0 -2
- {strling-2.2.0 → strling-2.3.0}/setup.py +2 -2
- strling-2.2.0/PKG-INFO +0 -287
- strling-2.2.0/README.md +0 -282
- strling-2.2.0/STRling/__init__.py +0 -2
- strling-2.2.0/STRling/patterns.py +0 -68
- strling-2.2.0/STRling/templates_v1.py +0 -77
- strling-2.2.0/STRling.egg-info/PKG-INFO +0 -287
- {strling-2.2.0 → strling-2.3.0}/STRling/simply/__init__.py +0 -0
- {strling-2.2.0 → strling-2.3.0}/STRling/simply/lookarounds.py +0 -0
- {strling-2.2.0 → strling-2.3.0}/STRling/simply/sets.py +0 -0
- {strling-2.2.0 → strling-2.3.0}/STRling.egg-info/dependency_links.txt +0 -0
- {strling-2.2.0 → strling-2.3.0}/STRling.egg-info/top_level.txt +0 -0
- {strling-2.2.0 → strling-2.3.0}/setup.cfg +0 -0
strling-2.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: STRling
|
|
3
|
+
Version: 2.3.0
|
|
4
|
+
Description-Content-Type: text/markdown
|
|
5
|
+
|
|
6
|
+
# STRling
|
|
7
|
+
|
|
8
|
+
## 🗺️ Project Overview
|
|
9
|
+
|
|
10
|
+
STRling is a next-generation production-grade syntax designed as a user interface for writing powerful regular expressions (RegEx) with an object-oriented approach and instructional error handling. STRling recognizes the cryptic nature of raw regular expression can be challenging and susceptibility to errors, which is why STRling looks and feels nothing like RegEx while maintaining the same power and flexibility. String validation should be simple and enjoyable, not a hassle. Best of all, STRling syntax is built upon the RegEx engine, making it fully compatible with all libraries that accept RegEx along with the traditional RegEx methods built-in to Python.
|
|
11
|
+
|
|
12
|
+
## 🗝️ Key Features
|
|
13
|
+
|
|
14
|
+
1. **Beginner Friendly:** You need ZERO knowledge of RegEx jargon to create powerful and clear to read patterns.
|
|
15
|
+
2. **Reliable Logic:** STRling exclusively utilizes built-in python libraries, making it a reliable package.
|
|
16
|
+
3. **Instructional Error Handling:** Errors inevitably occur by drafting invalid patterns, so STRling explains to the developer exactly what was done wrong and how to correct it.
|
|
17
|
+
4. **Consistent and Readable:** Make your projects clear and consistent by using STRling rather than the individual library string validators that each have their own syntax (Sqlite3, Sequelize, Postgres, WTForms... etc.).
|
|
18
|
+
|
|
19
|
+
These key features collectively emphasis and fortify the claim that STRling truly is a next-generation production-grade syntax for pattern handling.
|
|
20
|
+
|
|
21
|
+
## 🎯 Project Mission
|
|
22
|
+
|
|
23
|
+
Our mission is to make RegEx a distant and outdated syntax by abstracting the complexities of RegEx into a clean, readable, and powerful interface. We strive to simplify string operations and ensure that developers can focus on building their applications without the steep learning curve of traditional RegEx. The previous alternative to RegEx was to learn the string validation syntax specific to each user input library, but STRling aims to unify the disparate syntaxes found across various libraries and frameworks into one simple library using only built-in Python packages.
|
|
24
|
+
|
|
25
|
+
## 💾 Installation
|
|
26
|
+
|
|
27
|
+
Install STRling via pip:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
pip install STRling
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## ✨ STRling in action!
|
|
34
|
+
|
|
35
|
+
### 📑 [STRling Documentation on GitHub](https://github.com/TheCyberLocal/STRling/docs/strling_docs.md)
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from STRling import simply as s
|
|
39
|
+
import re
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# Let's make a phone number pattern for the formats below:
|
|
43
|
+
# - (123) 456-7890
|
|
44
|
+
# - 123-456-7890
|
|
45
|
+
# - 123 456 7890
|
|
46
|
+
# - 1234567890
|
|
47
|
+
|
|
48
|
+
# Separator: either space or hyphen
|
|
49
|
+
separator = s.in_chars(' -')
|
|
50
|
+
|
|
51
|
+
# Optional area code part: 123 even if in parenthesis like (123)
|
|
52
|
+
area_code = s.merge( # notice we use merge since we don't want to name the group with parenthesis
|
|
53
|
+
s.may('('), # Optional opening parenthesis
|
|
54
|
+
s.group('area_code', s.digit(3)), # Exactly 3 digits and named for later reference
|
|
55
|
+
s.may(')') # Optional closing parenthesis
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# Central part: 456
|
|
59
|
+
central_part = s.group('central_part', s.digit(3)) # Exactly 3 digits and named for later reference
|
|
60
|
+
|
|
61
|
+
# Last part: 7890
|
|
62
|
+
last_part = s.group("last_part", s.digit(4)) # Exactly 4 digits and named for later reference
|
|
63
|
+
|
|
64
|
+
# Combine all parts into the final phone number pattern
|
|
65
|
+
# Notice we don't name the whole pattern since we can already reference it
|
|
66
|
+
phone_number_pattern = s.merge(
|
|
67
|
+
area_code, # Area code part
|
|
68
|
+
s.may(separator), # Optional separator after area code
|
|
69
|
+
central_part, # Central 3 digits
|
|
70
|
+
s.may(separator), # Optional separator after area code
|
|
71
|
+
last_part # Last part with hyphen and 4 digits
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
# Example usage
|
|
75
|
+
# Note: To make a pattern a RegEx string compatible with other engines use `str(pattern)`.
|
|
76
|
+
example_text = "(123) 456-7890 and 123-456-7890"
|
|
77
|
+
pattern = re.compile(str(phone_number_pattern)) # Notice str(pattern)
|
|
78
|
+
matches = pattern.finditer(example_text)
|
|
79
|
+
|
|
80
|
+
for match in matches:
|
|
81
|
+
print("Full Match:", match.group())
|
|
82
|
+
print("Area Code:", match.group("area_code"))
|
|
83
|
+
print("Central Part:", match.group("central_part"))
|
|
84
|
+
print("Last Part:", match.group("last_part"))
|
|
85
|
+
print()
|
|
86
|
+
|
|
87
|
+
# Output:
|
|
88
|
+
# Full Match: (123) 456-7890
|
|
89
|
+
# Area Code: 123
|
|
90
|
+
# Central Part: 456
|
|
91
|
+
# Last Part: 7890
|
|
92
|
+
|
|
93
|
+
# Full Match: 123-456-7890
|
|
94
|
+
# Area Code: 123
|
|
95
|
+
# Central Part: 456
|
|
96
|
+
# Last Part: 7890
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Simplify your string validation and matching tasks with STRling, the all-in-one solution for developers who need a powerful yet user-friendly tool for working with strings. No longer write RegEx using complex jargon or the various syntaxes string validation specific to independent libraries. Download and start using STRling today!
|
|
100
|
+
|
|
101
|
+
## 🌎 Locations
|
|
102
|
+
[](https://pypi.org/project/STRling/)
|
|
103
|
+
[](https://github.com/TheCyberLocal/STRling)
|
|
104
|
+
|
|
105
|
+
## 🌐 Socials
|
|
106
|
+
[](https://linkedin.com/in/tzm01)
|
|
107
|
+
|
|
108
|
+
## 💖 Support
|
|
109
|
+
If you find my content helpful or interesting, consider buying me a coffee. Every cup is greatly appreciated and fuels my work!
|
|
110
|
+
|
|
111
|
+
[](https://buymeacoffee.com/thecyberlocal)
|
|
112
|
+
[](https://www.paypal.com/paypalme/TheCyberLocal)
|
|
113
|
+
[](https://www.venmo.com/TheCyberLocal)
|
strling-2.3.0/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# STRling
|
|
2
|
+
|
|
3
|
+
## 🗺️ Project Overview
|
|
4
|
+
|
|
5
|
+
STRling is a next-generation production-grade syntax designed as a user interface for writing powerful regular expressions (RegEx) with an object-oriented approach and instructional error handling. STRling recognizes the cryptic nature of raw regular expression can be challenging and susceptibility to errors, which is why STRling looks and feels nothing like RegEx while maintaining the same power and flexibility. String validation should be simple and enjoyable, not a hassle. Best of all, STRling syntax is built upon the RegEx engine, making it fully compatible with all libraries that accept RegEx along with the traditional RegEx methods built-in to Python.
|
|
6
|
+
|
|
7
|
+
## 🗝️ Key Features
|
|
8
|
+
|
|
9
|
+
1. **Beginner Friendly:** You need ZERO knowledge of RegEx jargon to create powerful and clear to read patterns.
|
|
10
|
+
2. **Reliable Logic:** STRling exclusively utilizes built-in python libraries, making it a reliable package.
|
|
11
|
+
3. **Instructional Error Handling:** Errors inevitably occur by drafting invalid patterns, so STRling explains to the developer exactly what was done wrong and how to correct it.
|
|
12
|
+
4. **Consistent and Readable:** Make your projects clear and consistent by using STRling rather than the individual library string validators that each have their own syntax (Sqlite3, Sequelize, Postgres, WTForms... etc.).
|
|
13
|
+
|
|
14
|
+
These key features collectively emphasis and fortify the claim that STRling truly is a next-generation production-grade syntax for pattern handling.
|
|
15
|
+
|
|
16
|
+
## 🎯 Project Mission
|
|
17
|
+
|
|
18
|
+
Our mission is to make RegEx a distant and outdated syntax by abstracting the complexities of RegEx into a clean, readable, and powerful interface. We strive to simplify string operations and ensure that developers can focus on building their applications without the steep learning curve of traditional RegEx. The previous alternative to RegEx was to learn the string validation syntax specific to each user input library, but STRling aims to unify the disparate syntaxes found across various libraries and frameworks into one simple library using only built-in Python packages.
|
|
19
|
+
|
|
20
|
+
## 💾 Installation
|
|
21
|
+
|
|
22
|
+
Install STRling via pip:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
pip install STRling
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## ✨ STRling in action!
|
|
29
|
+
|
|
30
|
+
### 📑 [STRling Documentation](./docs/strling_docs.md)
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from STRling import simply as s
|
|
34
|
+
import re
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# Let's make a phone number pattern for the formats below:
|
|
38
|
+
# - (123) 456-7890
|
|
39
|
+
# - 123-456-7890
|
|
40
|
+
# - 123 456 7890
|
|
41
|
+
# - 1234567890
|
|
42
|
+
|
|
43
|
+
# Separator: either space or hyphen
|
|
44
|
+
separator = s.in_chars(' -')
|
|
45
|
+
|
|
46
|
+
# Optional area code part: 123 even if in parenthesis like (123)
|
|
47
|
+
area_code = s.merge( # notice we use merge since we don't want to name the group with parenthesis
|
|
48
|
+
s.may('('), # Optional opening parenthesis
|
|
49
|
+
s.group('area_code', s.digit(3)), # Exactly 3 digits and named for later reference
|
|
50
|
+
s.may(')') # Optional closing parenthesis
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
# Central part: 456
|
|
54
|
+
central_part = s.group('central_part', s.digit(3)) # Exactly 3 digits and named for later reference
|
|
55
|
+
|
|
56
|
+
# Last part: 7890
|
|
57
|
+
last_part = s.group("last_part", s.digit(4)) # Exactly 4 digits and named for later reference
|
|
58
|
+
|
|
59
|
+
# Combine all parts into the final phone number pattern
|
|
60
|
+
# Notice we don't name the whole pattern since we can already reference it
|
|
61
|
+
phone_number_pattern = s.merge(
|
|
62
|
+
area_code, # Area code part
|
|
63
|
+
s.may(separator), # Optional separator after area code
|
|
64
|
+
central_part, # Central 3 digits
|
|
65
|
+
s.may(separator), # Optional separator after area code
|
|
66
|
+
last_part # Last part with hyphen and 4 digits
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# Example usage
|
|
70
|
+
# Note: To make a pattern a RegEx string compatible with other engines use `str(pattern)`.
|
|
71
|
+
example_text = "(123) 456-7890 and 123-456-7890"
|
|
72
|
+
pattern = re.compile(str(phone_number_pattern)) # Notice str(pattern)
|
|
73
|
+
matches = pattern.finditer(example_text)
|
|
74
|
+
|
|
75
|
+
for match in matches:
|
|
76
|
+
print("Full Match:", match.group())
|
|
77
|
+
print("Area Code:", match.group("area_code"))
|
|
78
|
+
print("Central Part:", match.group("central_part"))
|
|
79
|
+
print("Last Part:", match.group("last_part"))
|
|
80
|
+
print()
|
|
81
|
+
|
|
82
|
+
# Output:
|
|
83
|
+
# Full Match: (123) 456-7890
|
|
84
|
+
# Area Code: 123
|
|
85
|
+
# Central Part: 456
|
|
86
|
+
# Last Part: 7890
|
|
87
|
+
|
|
88
|
+
# Full Match: 123-456-7890
|
|
89
|
+
# Area Code: 123
|
|
90
|
+
# Central Part: 456
|
|
91
|
+
# Last Part: 7890
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Simplify your string validation and matching tasks with STRling, the all-in-one solution for developers who need a powerful yet user-friendly tool for working with strings. No longer write RegEx using complex jargon or the various syntaxes string validation specific to independent libraries. Download and start using STRling today!
|
|
95
|
+
|
|
96
|
+
## 🌎 Locations
|
|
97
|
+
[](https://pypi.org/project/STRling/)
|
|
98
|
+
[](https://github.com/TheCyberLocal/STRling)
|
|
99
|
+
|
|
100
|
+
## 🌐 Socials
|
|
101
|
+
[](https://linkedin.com/in/tzm01)
|
|
102
|
+
|
|
103
|
+
## 💖 Support
|
|
104
|
+
If you find my content helpful or interesting, consider buying me a coffee. Every cup is greatly appreciated and fuels my work!
|
|
105
|
+
|
|
106
|
+
[](https://buymeacoffee.com/thecyberlocal)
|
|
107
|
+
[](https://www.paypal.com/paypalme/TheCyberLocal)
|
|
108
|
+
[](https://www.venmo.com/TheCyberLocal)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import simply
|
|
@@ -77,7 +77,7 @@ def any_of(*patterns):
|
|
|
77
77
|
|
|
78
78
|
sub_names = named_group_counts.keys()
|
|
79
79
|
|
|
80
|
-
joined = '|'.join(
|
|
80
|
+
joined = '|'.join(str(p) for p in clean_patterns)
|
|
81
81
|
new_pattern = f'(?:{joined})'
|
|
82
82
|
|
|
83
83
|
return Pattern(new_pattern, composite=True, named_groups=sub_names)
|
|
@@ -96,11 +96,11 @@ class Pattern:
|
|
|
96
96
|
raise STRlingError(message)
|
|
97
97
|
|
|
98
98
|
# If min_rep or max_rep are specified out of valid range
|
|
99
|
-
if min_rep is not None and min_rep <
|
|
99
|
+
if min_rep is not None and min_rep < 0 or max_rep is not None and max_rep < 0:
|
|
100
100
|
message = """
|
|
101
101
|
Method: Pattern.__call__(min_rep, max_rep)
|
|
102
102
|
|
|
103
|
-
The `min_rep`
|
|
103
|
+
The `min_rep` and `max_rep` must be 0 or greater.
|
|
104
104
|
"""
|
|
105
105
|
raise STRlingError(message)
|
|
106
106
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
from .pattern import Pattern
|
|
2
|
+
from .pattern import Pattern, lit
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
@@ -7,6 +7,81 @@ from .pattern import Pattern
|
|
|
7
7
|
# Custom Char Sets
|
|
8
8
|
########
|
|
9
9
|
|
|
10
|
+
def special_char(min_rep: int = None, max_rep: int = None):
|
|
11
|
+
"""
|
|
12
|
+
Matches any special character. => !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
|
|
13
|
+
|
|
14
|
+
Parameters: (min_rep/exact_rep, max_rep)
|
|
15
|
+
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
16
|
+
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
17
|
+
|
|
18
|
+
Special Cases:
|
|
19
|
+
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
20
|
+
- If `max_rep` is 0, it means there is no upper limit.
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
- An instance of the Pattern class.
|
|
24
|
+
"""
|
|
25
|
+
special = lit("""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~""")
|
|
26
|
+
return Pattern(f'[{str(special)}]', custom_set=True)(min_rep, max_rep)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def not_special_char(min_rep: int = None, max_rep: int = None):
|
|
30
|
+
"""
|
|
31
|
+
Matches anything but a special character. => !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
|
|
32
|
+
|
|
33
|
+
Parameters: (min_rep/exact_rep, max_rep)
|
|
34
|
+
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
35
|
+
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
36
|
+
|
|
37
|
+
Special Cases:
|
|
38
|
+
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
39
|
+
- If `max_rep` is 0, it means there is no upper limit.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
- An instance of the Pattern class.
|
|
43
|
+
"""
|
|
44
|
+
special = lit("""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~""")
|
|
45
|
+
return Pattern(f'[^{str(special)}]', custom_set=True, negated=True)(min_rep, max_rep)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def word_char(min_rep: int = None, max_rep: int = None):
|
|
49
|
+
"""
|
|
50
|
+
Matches any word character.
|
|
51
|
+
A word character is any case letter, a digit, or an underscore.
|
|
52
|
+
|
|
53
|
+
Parameters: (min_rep/exact_rep, max_rep)
|
|
54
|
+
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
55
|
+
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
56
|
+
|
|
57
|
+
Special Cases:
|
|
58
|
+
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
59
|
+
- If `max_rep` is 0, it means there is no upper limit.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
- An instance of the Pattern class.
|
|
63
|
+
"""
|
|
64
|
+
return Pattern(r'[a-zA-Z0-9_]', custom_set=True)(min_rep, max_rep)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def not_word_char(min_rep: int = None, max_rep: int = None):
|
|
68
|
+
"""
|
|
69
|
+
Matches anything but a word character.
|
|
70
|
+
A word character is any case letter, a digit, or an underscore.
|
|
71
|
+
|
|
72
|
+
Parameters: (min_rep/exact_rep, max_rep)
|
|
73
|
+
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
74
|
+
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
75
|
+
|
|
76
|
+
Special Cases:
|
|
77
|
+
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
78
|
+
- If `max_rep` is 0, it means there is no upper limit.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
- An instance of the Pattern class.
|
|
82
|
+
"""
|
|
83
|
+
return Pattern(r'[^a-zA-Z0-9_]', custom_set=True, negated=True)(min_rep, max_rep)
|
|
84
|
+
|
|
10
85
|
|
|
11
86
|
def letter(min_rep: int = None, max_rep: int = None):
|
|
12
87
|
"""
|
|
@@ -158,6 +233,44 @@ def not_digit(min_rep: int = None, max_rep: int = None):
|
|
|
158
233
|
return Pattern(r'\D')(min_rep, max_rep)
|
|
159
234
|
|
|
160
235
|
|
|
236
|
+
def hex_digit(min_rep: int = None, max_rep: int = None):
|
|
237
|
+
"""
|
|
238
|
+
Matches any hex-digit character.
|
|
239
|
+
A hex-digit character is any letter A through F (uppercase or lowercase) or any digit (0-9).
|
|
240
|
+
|
|
241
|
+
Parameters: (min_rep/exact_rep, max_rep)
|
|
242
|
+
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
243
|
+
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
244
|
+
|
|
245
|
+
Special Cases:
|
|
246
|
+
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
247
|
+
- If `max_rep` is 0, it means there is no upper limit.
|
|
248
|
+
|
|
249
|
+
Returns:
|
|
250
|
+
- An instance of the Pattern class.
|
|
251
|
+
"""
|
|
252
|
+
return Pattern(r'[A-Fa-f\d]')(min_rep, max_rep)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def not_hex_digit(min_rep: int = None, max_rep: int = None):
|
|
256
|
+
"""
|
|
257
|
+
Matches anything but a hex-digit character.
|
|
258
|
+
A hex-digit character is any letter A through F (uppercase or lowercase) or any digit (0-9).
|
|
259
|
+
|
|
260
|
+
Parameters: (min_rep/exact_rep, max_rep)
|
|
261
|
+
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
262
|
+
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
263
|
+
|
|
264
|
+
Special Cases:
|
|
265
|
+
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
266
|
+
- If `max_rep` is 0, it means there is no upper limit.
|
|
267
|
+
|
|
268
|
+
Returns:
|
|
269
|
+
- An instance of the Pattern class.
|
|
270
|
+
"""
|
|
271
|
+
return Pattern(r'[^A-Fa-f\d]')(min_rep, max_rep)
|
|
272
|
+
|
|
273
|
+
|
|
161
274
|
def whitespace(min_rep: int = None, max_rep: int = None):
|
|
162
275
|
"""
|
|
163
276
|
Matches any whitespace character. (Whitespaces include space, tab, newline, carriage return, etc.)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: STRling
|
|
3
|
+
Version: 2.3.0
|
|
4
|
+
Description-Content-Type: text/markdown
|
|
5
|
+
|
|
6
|
+
# STRling
|
|
7
|
+
|
|
8
|
+
## 🗺️ Project Overview
|
|
9
|
+
|
|
10
|
+
STRling is a next-generation production-grade syntax designed as a user interface for writing powerful regular expressions (RegEx) with an object-oriented approach and instructional error handling. STRling recognizes the cryptic nature of raw regular expression can be challenging and susceptibility to errors, which is why STRling looks and feels nothing like RegEx while maintaining the same power and flexibility. String validation should be simple and enjoyable, not a hassle. Best of all, STRling syntax is built upon the RegEx engine, making it fully compatible with all libraries that accept RegEx along with the traditional RegEx methods built-in to Python.
|
|
11
|
+
|
|
12
|
+
## 🗝️ Key Features
|
|
13
|
+
|
|
14
|
+
1. **Beginner Friendly:** You need ZERO knowledge of RegEx jargon to create powerful and clear to read patterns.
|
|
15
|
+
2. **Reliable Logic:** STRling exclusively utilizes built-in python libraries, making it a reliable package.
|
|
16
|
+
3. **Instructional Error Handling:** Errors inevitably occur by drafting invalid patterns, so STRling explains to the developer exactly what was done wrong and how to correct it.
|
|
17
|
+
4. **Consistent and Readable:** Make your projects clear and consistent by using STRling rather than the individual library string validators that each have their own syntax (Sqlite3, Sequelize, Postgres, WTForms... etc.).
|
|
18
|
+
|
|
19
|
+
These key features collectively emphasis and fortify the claim that STRling truly is a next-generation production-grade syntax for pattern handling.
|
|
20
|
+
|
|
21
|
+
## 🎯 Project Mission
|
|
22
|
+
|
|
23
|
+
Our mission is to make RegEx a distant and outdated syntax by abstracting the complexities of RegEx into a clean, readable, and powerful interface. We strive to simplify string operations and ensure that developers can focus on building their applications without the steep learning curve of traditional RegEx. The previous alternative to RegEx was to learn the string validation syntax specific to each user input library, but STRling aims to unify the disparate syntaxes found across various libraries and frameworks into one simple library using only built-in Python packages.
|
|
24
|
+
|
|
25
|
+
## 💾 Installation
|
|
26
|
+
|
|
27
|
+
Install STRling via pip:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
pip install STRling
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## ✨ STRling in action!
|
|
34
|
+
|
|
35
|
+
### 📑 [STRling Documentation on GitHub](https://github.com/TheCyberLocal/STRling/docs/strling_docs.md)
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from STRling import simply as s
|
|
39
|
+
import re
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# Let's make a phone number pattern for the formats below:
|
|
43
|
+
# - (123) 456-7890
|
|
44
|
+
# - 123-456-7890
|
|
45
|
+
# - 123 456 7890
|
|
46
|
+
# - 1234567890
|
|
47
|
+
|
|
48
|
+
# Separator: either space or hyphen
|
|
49
|
+
separator = s.in_chars(' -')
|
|
50
|
+
|
|
51
|
+
# Optional area code part: 123 even if in parenthesis like (123)
|
|
52
|
+
area_code = s.merge( # notice we use merge since we don't want to name the group with parenthesis
|
|
53
|
+
s.may('('), # Optional opening parenthesis
|
|
54
|
+
s.group('area_code', s.digit(3)), # Exactly 3 digits and named for later reference
|
|
55
|
+
s.may(')') # Optional closing parenthesis
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# Central part: 456
|
|
59
|
+
central_part = s.group('central_part', s.digit(3)) # Exactly 3 digits and named for later reference
|
|
60
|
+
|
|
61
|
+
# Last part: 7890
|
|
62
|
+
last_part = s.group("last_part", s.digit(4)) # Exactly 4 digits and named for later reference
|
|
63
|
+
|
|
64
|
+
# Combine all parts into the final phone number pattern
|
|
65
|
+
# Notice we don't name the whole pattern since we can already reference it
|
|
66
|
+
phone_number_pattern = s.merge(
|
|
67
|
+
area_code, # Area code part
|
|
68
|
+
s.may(separator), # Optional separator after area code
|
|
69
|
+
central_part, # Central 3 digits
|
|
70
|
+
s.may(separator), # Optional separator after area code
|
|
71
|
+
last_part # Last part with hyphen and 4 digits
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
# Example usage
|
|
75
|
+
# Note: To make a pattern a RegEx string compatible with other engines use `str(pattern)`.
|
|
76
|
+
example_text = "(123) 456-7890 and 123-456-7890"
|
|
77
|
+
pattern = re.compile(str(phone_number_pattern)) # Notice str(pattern)
|
|
78
|
+
matches = pattern.finditer(example_text)
|
|
79
|
+
|
|
80
|
+
for match in matches:
|
|
81
|
+
print("Full Match:", match.group())
|
|
82
|
+
print("Area Code:", match.group("area_code"))
|
|
83
|
+
print("Central Part:", match.group("central_part"))
|
|
84
|
+
print("Last Part:", match.group("last_part"))
|
|
85
|
+
print()
|
|
86
|
+
|
|
87
|
+
# Output:
|
|
88
|
+
# Full Match: (123) 456-7890
|
|
89
|
+
# Area Code: 123
|
|
90
|
+
# Central Part: 456
|
|
91
|
+
# Last Part: 7890
|
|
92
|
+
|
|
93
|
+
# Full Match: 123-456-7890
|
|
94
|
+
# Area Code: 123
|
|
95
|
+
# Central Part: 456
|
|
96
|
+
# Last Part: 7890
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Simplify your string validation and matching tasks with STRling, the all-in-one solution for developers who need a powerful yet user-friendly tool for working with strings. No longer write RegEx using complex jargon or the various syntaxes string validation specific to independent libraries. Download and start using STRling today!
|
|
100
|
+
|
|
101
|
+
## 🌎 Locations
|
|
102
|
+
[](https://pypi.org/project/STRling/)
|
|
103
|
+
[](https://github.com/TheCyberLocal/STRling)
|
|
104
|
+
|
|
105
|
+
## 🌐 Socials
|
|
106
|
+
[](https://linkedin.com/in/tzm01)
|
|
107
|
+
|
|
108
|
+
## 💖 Support
|
|
109
|
+
If you find my content helpful or interesting, consider buying me a coffee. Every cup is greatly appreciated and fuels my work!
|
|
110
|
+
|
|
111
|
+
[](https://buymeacoffee.com/thecyberlocal)
|
|
112
|
+
[](https://www.paypal.com/paypalme/TheCyberLocal)
|
|
113
|
+
[](https://www.venmo.com/TheCyberLocal)
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
from setuptools import setup, find_packages
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
with open('
|
|
7
|
+
with open('./docs/pypi_docs.md', 'r') as f:
|
|
8
8
|
description = f.read()
|
|
9
9
|
|
|
10
10
|
setup(
|
|
11
11
|
name='STRling',
|
|
12
|
-
version='2.
|
|
12
|
+
version='2.3.0',
|
|
13
13
|
packages=find_packages(),
|
|
14
14
|
install_requires=[
|
|
15
15
|
# Add dependencies here.
|