STRling 2.4.3__tar.gz → 2.4.4__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.4.3 → strling-2.4.4}/PKG-INFO +10 -2
- {strling-2.4.3 → strling-2.4.4}/README.md +4 -1
- {strling-2.4.3 → strling-2.4.4}/STRling/simply/constructors.py +61 -79
- {strling-2.4.3 → strling-2.4.4}/STRling/simply/lookarounds.py +28 -31
- {strling-2.4.3 → strling-2.4.4}/STRling/simply/pattern.py +7 -15
- {strling-2.4.3 → strling-2.4.4}/STRling/simply/sets.py +58 -69
- {strling-2.4.3 → strling-2.4.4}/STRling/simply/static.py +44 -139
- {strling-2.4.3 → strling-2.4.4}/STRling.egg-info/PKG-INFO +10 -2
- {strling-2.4.3 → strling-2.4.4}/setup.py +1 -1
- {strling-2.4.3 → strling-2.4.4}/STRling/__init__.py +0 -0
- {strling-2.4.3 → strling-2.4.4}/STRling/simply/__init__.py +0 -0
- {strling-2.4.3 → strling-2.4.4}/STRling.egg-info/SOURCES.txt +0 -0
- {strling-2.4.3 → strling-2.4.4}/STRling.egg-info/dependency_links.txt +0 -0
- {strling-2.4.3 → strling-2.4.4}/STRling.egg-info/top_level.txt +0 -0
- {strling-2.4.3 → strling-2.4.4}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: STRling
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.4
|
|
4
4
|
Description-Content-Type: text/markdown
|
|
5
5
|
|
|
6
6
|
# STRling
|
|
@@ -99,18 +99,26 @@ for match in matches:
|
|
|
99
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
100
|
|
|
101
101
|
## 🌎 Locations
|
|
102
|
+
|
|
102
103
|
### STRling for Python
|
|
104
|
+
|
|
103
105
|
[](https://pypi.org/project/STRling/)
|
|
104
106
|
[](https://github.com/TheCyberLocal/STRling-Py)
|
|
105
107
|
|
|
106
108
|
### STRling for JavaScript
|
|
107
|
-
|
|
109
|
+
|
|
110
|
+
[](https://www.npmjs.com/package/@thecyberlocal/strling)
|
|
108
111
|
[](https://github.com/TheCyberLocal/STRling-JS)
|
|
109
112
|
|
|
110
113
|
## 🌐 Socials
|
|
114
|
+
|
|
111
115
|
[](https://linkedin.com/in/tzm01)
|
|
116
|
+
[](https://github.com/TheCyberLocal)
|
|
117
|
+
[](https://pypi.org/user/TheCyberLocal/)
|
|
118
|
+
[](https://www.npmjs.com/~thecyberlocal)
|
|
112
119
|
|
|
113
120
|
## 💖 Support
|
|
121
|
+
|
|
114
122
|
If you find my content helpful or interesting, consider buying me a coffee. Every cup is greatly appreciated and fuels my work!
|
|
115
123
|
|
|
116
124
|
[](https://buymeacoffee.com/thecyberlocal)
|
|
@@ -99,11 +99,14 @@ Simplify your string validation and matching tasks with STRling, the all-in-one
|
|
|
99
99
|
[](https://github.com/TheCyberLocal/STRling-Py)
|
|
100
100
|
|
|
101
101
|
### STRling for JavaScript
|
|
102
|
-
[](https://www.npmjs.com/package/@thecyberlocal/strling)
|
|
103
103
|
[](https://github.com/TheCyberLocal/STRling-JS)
|
|
104
104
|
|
|
105
105
|
## 🌐 Socials
|
|
106
106
|
[](https://linkedin.com/in/tzm01)
|
|
107
|
+
[](https://github.com/TheCyberLocal)
|
|
108
|
+
[](https://pypi.org/user/TheCyberLocal/)
|
|
109
|
+
[](https://www.npmjs.com/~thecyberlocal)
|
|
107
110
|
|
|
108
111
|
## 💖 Support
|
|
109
112
|
If you find my content helpful or interesting, consider buying me a coffee. Every cup is greatly appreciated and fuels my work!
|
|
@@ -1,38 +1,29 @@
|
|
|
1
|
-
|
|
2
1
|
from .pattern import STRlingError, Pattern, lit
|
|
3
2
|
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
############################
|
|
7
|
-
# Constructor Methods
|
|
8
|
-
########
|
|
9
|
-
|
|
10
|
-
|
|
11
4
|
def any_of(*patterns):
|
|
12
5
|
"""
|
|
13
6
|
Matches any provided pattern, including patterns consisting of subpatterns.
|
|
14
7
|
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
Parameters:
|
|
9
|
+
- *patterns (Pattern/str): One or more patterns to be matched.
|
|
17
10
|
|
|
18
|
-
|
|
11
|
+
Returns:
|
|
12
|
+
- An instance of the Pattern class.
|
|
19
13
|
|
|
20
|
-
|
|
14
|
+
Examples:
|
|
15
|
+
```
|
|
16
|
+
# Matches 3 digits followed by 3 letters.
|
|
17
|
+
pattern1 = s.merge(s.digit(3), s.letter(3))
|
|
21
18
|
|
|
19
|
+
# Matches 3 letters followed by 3 digits.
|
|
22
20
|
pattern2 = s.merge(s.letter(3), s.digit(3))
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
# Matches either pattern1 or pattern2.
|
|
26
23
|
either_pattern = s.any_of(pattern1, pattern2)
|
|
27
|
-
|
|
28
|
-
Parameters:
|
|
29
|
-
- *patterns (Pattern/str): One or more patterns to be matched.
|
|
30
|
-
|
|
31
|
-
Returns:
|
|
32
|
-
- Pattern: A Pattern object representing the OR combination of the given patterns.
|
|
24
|
+
```
|
|
33
25
|
"""
|
|
34
26
|
|
|
35
|
-
# Check all patterns are instance of Pattern or str
|
|
36
27
|
clean_patterns = []
|
|
37
28
|
for pattern in patterns:
|
|
38
29
|
if isinstance(pattern, str):
|
|
@@ -51,9 +42,7 @@ def any_of(*patterns):
|
|
|
51
42
|
clean_patterns.append(pattern)
|
|
52
43
|
|
|
53
44
|
|
|
54
|
-
# Count named groups and raise error if not unique
|
|
55
45
|
named_group_counts = {}
|
|
56
|
-
|
|
57
46
|
for pattern in clean_patterns:
|
|
58
47
|
for group_name in pattern.named_groups:
|
|
59
48
|
if group_name in named_group_counts:
|
|
@@ -86,21 +75,21 @@ def may(*patterns):
|
|
|
86
75
|
"""
|
|
87
76
|
Optionally matches the provided patterns. If this pattern is absent, surrounding patterns can still match.
|
|
88
77
|
|
|
89
|
-
Example: simply as s
|
|
90
|
-
- Matches any letter, along with any trailing digit.
|
|
91
|
-
|
|
92
|
-
pattern = s.merge(s.letter(), s.may(s.digit()))
|
|
93
|
-
|
|
94
|
-
In the text, "AB2" the pattern above matches 'A' and 'B2'.
|
|
95
|
-
|
|
96
78
|
Parameters:
|
|
97
79
|
- *patterns (Pattern/str): One or more patterns to be optionally matched.
|
|
98
80
|
|
|
99
81
|
Returns:
|
|
100
|
-
-
|
|
82
|
+
- An instance of the Pattern class.
|
|
83
|
+
|
|
84
|
+
Examples:
|
|
85
|
+
```
|
|
86
|
+
# Matches any letter, along with any trailing digit.
|
|
87
|
+
pattern = s.merge(s.letter(), s.may(s.digit()))
|
|
88
|
+
|
|
89
|
+
# In the text "AB2" the pattern above matches 'A' and 'B2'.
|
|
90
|
+
```
|
|
101
91
|
"""
|
|
102
92
|
|
|
103
|
-
# Check all patterns are instance of Pattern or str
|
|
104
93
|
clean_patterns = []
|
|
105
94
|
for pattern in patterns:
|
|
106
95
|
if isinstance(pattern, str):
|
|
@@ -119,9 +108,7 @@ def may(*patterns):
|
|
|
119
108
|
clean_patterns.append(pattern)
|
|
120
109
|
|
|
121
110
|
|
|
122
|
-
# Count named groups and raise error if not unique
|
|
123
111
|
named_group_counts = {}
|
|
124
|
-
|
|
125
112
|
for pattern in clean_patterns:
|
|
126
113
|
for group_name in pattern.named_groups:
|
|
127
114
|
if group_name in named_group_counts:
|
|
@@ -156,19 +143,19 @@ def merge(*patterns):
|
|
|
156
143
|
"""
|
|
157
144
|
Combines the provided patterns into one larger pattern.
|
|
158
145
|
|
|
159
|
-
Example: simply as s
|
|
160
|
-
- Matches any digit, comma, or period.
|
|
161
|
-
|
|
162
|
-
merged_pattern = s.merge(s.digit(), ',.')
|
|
163
|
-
|
|
164
146
|
Parameters:
|
|
165
147
|
- *patterns (Pattern/str): One or more patterns to be concatenated.
|
|
166
148
|
|
|
167
149
|
Returns:
|
|
168
|
-
-
|
|
150
|
+
- An instance of the Pattern class.
|
|
151
|
+
|
|
152
|
+
Examples:
|
|
153
|
+
```
|
|
154
|
+
# Matches any digit followed by a comma and period.
|
|
155
|
+
merged_pattern = s.merge(s.digit(), ',.')
|
|
156
|
+
```
|
|
169
157
|
"""
|
|
170
158
|
|
|
171
|
-
# Check all patterns are instance of Pattern or str
|
|
172
159
|
clean_patterns = []
|
|
173
160
|
for pattern in patterns:
|
|
174
161
|
if isinstance(pattern, str):
|
|
@@ -187,9 +174,7 @@ def merge(*patterns):
|
|
|
187
174
|
clean_patterns.append(pattern)
|
|
188
175
|
|
|
189
176
|
|
|
190
|
-
# Count named groups and raise error if not unique
|
|
191
177
|
named_group_counts = {}
|
|
192
|
-
|
|
193
178
|
for pattern in clean_patterns:
|
|
194
179
|
for group_name in pattern.named_groups:
|
|
195
180
|
if group_name in named_group_counts:
|
|
@@ -222,31 +207,31 @@ def capture(*patterns):
|
|
|
222
207
|
"""
|
|
223
208
|
Creates a numbered group that can be indexed for extracting this part of the match.
|
|
224
209
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
s.capture(s.digit(), s.letter())(1, 2) <== INVALID
|
|
210
|
+
Parameters:
|
|
211
|
+
- *patterns (Pattern/str): One or more patterns to be captured.
|
|
228
212
|
|
|
229
|
-
|
|
213
|
+
Returns:
|
|
214
|
+
- An instance of the Pattern class.
|
|
230
215
|
|
|
231
|
-
|
|
216
|
+
Ranges:
|
|
217
|
+
```
|
|
218
|
+
# Captures CANNOT be invoked with a range.
|
|
219
|
+
s.capture(s.digit(), s.letter())(1, 2) # <== INVALID
|
|
232
220
|
|
|
233
|
-
|
|
234
|
-
|
|
221
|
+
# Captures CAN be invoked with a number of copies.
|
|
222
|
+
s.capture(s.digit(), s.letter())(3) # <== VALID
|
|
223
|
+
```
|
|
235
224
|
|
|
225
|
+
Examples:
|
|
226
|
+
```
|
|
227
|
+
# Matches any digit followed by a comma and period.
|
|
236
228
|
captured_pattern = s.capture(s.digit(), ',.')
|
|
229
|
+
```
|
|
237
230
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
- *patterns (Pattern/str): One or more patterns to be captured.
|
|
241
|
-
|
|
242
|
-
Returns:
|
|
243
|
-
- Pattern: A Pattern object representing the capturing group of the given patterns.
|
|
244
|
-
|
|
245
|
-
Referencing: simply as s
|
|
231
|
+
Referencing:
|
|
232
|
+
```
|
|
246
233
|
three_digit_group = s.capture(s.digit(3))
|
|
247
|
-
|
|
248
234
|
four_groups_of_three = three_digit_groups(4)
|
|
249
|
-
|
|
250
235
|
example_text = "Here is a number: 111222333444"
|
|
251
236
|
|
|
252
237
|
match = re.search(str(four_groups_of_three), example_text) # Notice str(pattern)
|
|
@@ -263,9 +248,9 @@ def capture(*patterns):
|
|
|
263
248
|
# Second: 222
|
|
264
249
|
# Third: 333
|
|
265
250
|
# Fourth: 444
|
|
251
|
+
```
|
|
266
252
|
"""
|
|
267
253
|
|
|
268
|
-
# Check all patterns are instance of Pattern or str
|
|
269
254
|
clean_patterns = []
|
|
270
255
|
for pattern in patterns:
|
|
271
256
|
if isinstance(pattern, str):
|
|
@@ -284,9 +269,7 @@ def capture(*patterns):
|
|
|
284
269
|
clean_patterns.append(pattern)
|
|
285
270
|
|
|
286
271
|
|
|
287
|
-
# Count named groups and raise error if not unique
|
|
288
272
|
named_group_counts = {}
|
|
289
|
-
|
|
290
273
|
for pattern in clean_patterns:
|
|
291
274
|
for group_name in pattern.named_groups:
|
|
292
275
|
if group_name in named_group_counts:
|
|
@@ -319,33 +302,34 @@ def group(name, *patterns):
|
|
|
319
302
|
"""
|
|
320
303
|
Creates a unique named group that can be referenced for extracting this part of the match.
|
|
321
304
|
|
|
322
|
-
- Groups CANNOT be invoked with a range.
|
|
323
|
-
|
|
324
|
-
s.group('name', s.digit())(1, 2) <== INVALID
|
|
325
|
-
|
|
326
|
-
Example: simply as s
|
|
327
|
-
- Matches any digit followed by a comma and period.
|
|
328
|
-
|
|
329
|
-
named_pattern = s.group('my_group', s.digit(), ',.')
|
|
330
|
-
|
|
331
305
|
Parameters:
|
|
332
306
|
- name (str): The name of the capturing group.
|
|
333
307
|
- *patterns (Pattern/str): One or more patterns to be captured.
|
|
334
308
|
|
|
335
309
|
Returns:
|
|
336
|
-
-
|
|
310
|
+
- An instance of the Pattern class.
|
|
337
311
|
|
|
338
|
-
|
|
339
|
-
|
|
312
|
+
Ranges:
|
|
313
|
+
```
|
|
314
|
+
# Groups CANNOT be invoked with a range.
|
|
315
|
+
s.group('name', s.digit())(1, 2) # <== INVALID
|
|
316
|
+
```
|
|
340
317
|
|
|
341
|
-
|
|
318
|
+
Examples:
|
|
319
|
+
```
|
|
320
|
+
# Matches any digit followed by a comma and period.
|
|
321
|
+
named_pattern = s.group('my_group', s.digit(), ',.')
|
|
322
|
+
```
|
|
342
323
|
|
|
324
|
+
Referencing:
|
|
325
|
+
```
|
|
326
|
+
first = s.group("first", s.digit(3))
|
|
327
|
+
second = s.group("second", s.digit(3))
|
|
343
328
|
third = s.group("third", s.digit(4))
|
|
344
329
|
|
|
345
330
|
phone_number_pattern = s.merge(first, "-", second, "-", third)
|
|
346
331
|
|
|
347
332
|
example_text = "Here is a phone number: 123-456-7890."
|
|
348
|
-
|
|
349
333
|
match = re.search(str(phone_number_pattern), example_text) # Notice str(pattern)
|
|
350
334
|
|
|
351
335
|
print("Full Match:", match.group())
|
|
@@ -358,6 +342,7 @@ def group(name, *patterns):
|
|
|
358
342
|
# First: 123
|
|
359
343
|
# Second: 456
|
|
360
344
|
# Third: 7890
|
|
345
|
+
```
|
|
361
346
|
"""
|
|
362
347
|
|
|
363
348
|
if not isinstance(name, str):
|
|
@@ -370,7 +355,6 @@ def group(name, *patterns):
|
|
|
370
355
|
raise STRlingError(message)
|
|
371
356
|
|
|
372
357
|
|
|
373
|
-
# Check all patterns are instance of Pattern or str
|
|
374
358
|
clean_patterns = []
|
|
375
359
|
for pattern in patterns:
|
|
376
360
|
if isinstance(pattern, str):
|
|
@@ -389,9 +373,7 @@ def group(name, *patterns):
|
|
|
389
373
|
clean_patterns.append(pattern)
|
|
390
374
|
|
|
391
375
|
|
|
392
|
-
# Count named groups and raise error if not unique
|
|
393
376
|
named_group_counts = {}
|
|
394
|
-
|
|
395
377
|
for pattern in clean_patterns:
|
|
396
378
|
for group_name in pattern.named_groups:
|
|
397
379
|
if group_name in named_group_counts:
|
|
@@ -1,27 +1,21 @@
|
|
|
1
|
-
|
|
2
1
|
from .pattern import STRlingError, Pattern, lit
|
|
3
2
|
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
############################
|
|
7
|
-
# Lookarounds
|
|
8
|
-
########
|
|
9
|
-
|
|
10
|
-
|
|
11
4
|
def ahead(pattern):
|
|
12
5
|
"""
|
|
13
6
|
A positive lookahead checks for the presence of the specified pattern after the current position without including it in the result.
|
|
14
7
|
|
|
15
|
-
Example: simply as s
|
|
16
|
-
- Only matches a digit followed by a letter.
|
|
17
|
-
|
|
18
|
-
my_pattern = s.merge(s.digit(), s.ahead(s.letter()))
|
|
19
|
-
|
|
20
8
|
Parameters:
|
|
21
9
|
- pattern (Pattern/str): The pattern to look ahead for.
|
|
22
10
|
|
|
23
11
|
Returns:
|
|
24
|
-
-
|
|
12
|
+
- An instance of the Pattern class.
|
|
13
|
+
|
|
14
|
+
Examples:
|
|
15
|
+
```
|
|
16
|
+
# Only matches a digit followed by a letter.
|
|
17
|
+
my_pattern = s.merge(s.digit(), s.ahead(s.letter()))
|
|
18
|
+
```
|
|
25
19
|
"""
|
|
26
20
|
|
|
27
21
|
if isinstance(pattern, str):
|
|
@@ -43,16 +37,17 @@ def not_ahead(pattern):
|
|
|
43
37
|
"""
|
|
44
38
|
A negative lookahead checks for the absence of the specified pattern after the current position without including it in the result.
|
|
45
39
|
|
|
46
|
-
Example: simply as s
|
|
47
|
-
- Only matches a digit if not followed by a letter.
|
|
48
|
-
|
|
49
|
-
my_pattern = s.merge(s.digit(), s.not_ahead(s.letter()))
|
|
50
|
-
|
|
51
40
|
Parameters:
|
|
52
41
|
- pattern (Pattern/str): The pattern to look ahead for and ensure is absent.
|
|
53
42
|
|
|
54
43
|
Returns:
|
|
55
|
-
-
|
|
44
|
+
- An instance of the Pattern class.
|
|
45
|
+
|
|
46
|
+
Examples:
|
|
47
|
+
```
|
|
48
|
+
# Only matches a digit if not followed by a letter.
|
|
49
|
+
my_pattern = s.merge(s.digit(), s.not_ahead(s.letter()))
|
|
50
|
+
```
|
|
56
51
|
"""
|
|
57
52
|
|
|
58
53
|
if isinstance(pattern, str):
|
|
@@ -74,16 +69,17 @@ def behind(pattern):
|
|
|
74
69
|
"""
|
|
75
70
|
A positive lookbehind checks for the presence of the specified pattern before the current position without including it in the result.
|
|
76
71
|
|
|
77
|
-
Example: simply as s
|
|
78
|
-
- Only matches a letter preceded by a digit.
|
|
79
|
-
|
|
80
|
-
my_pattern = s.merge(s.behind(s.digit()), s.letter())
|
|
81
|
-
|
|
82
72
|
Parameters:
|
|
83
73
|
- pattern (Pattern/str): The pattern to look behind for.
|
|
84
74
|
|
|
85
75
|
Returns:
|
|
86
|
-
-
|
|
76
|
+
- An instance of the Pattern class.
|
|
77
|
+
|
|
78
|
+
Examples:
|
|
79
|
+
```
|
|
80
|
+
# Only matches a letter preceded by a digit.
|
|
81
|
+
my_pattern = s.merge(s.behind(s.digit()), s.letter())
|
|
82
|
+
```
|
|
87
83
|
"""
|
|
88
84
|
|
|
89
85
|
if isinstance(pattern, str):
|
|
@@ -105,16 +101,17 @@ def not_behind(pattern):
|
|
|
105
101
|
"""
|
|
106
102
|
A negative lookbehind checks for the absence of the specified pattern before the current position without including it in the result.
|
|
107
103
|
|
|
108
|
-
Example: simply as s
|
|
109
|
-
- Only matches a letter if not preceded by a digit.
|
|
110
|
-
|
|
111
|
-
my_pattern = s.merge(s.behind(s.digit()), s.letter())
|
|
112
|
-
|
|
113
104
|
Parameters:
|
|
114
105
|
- pattern (Pattern/str): The pattern to look behind for and ensure is absent.
|
|
115
106
|
|
|
116
107
|
Returns:
|
|
117
|
-
-
|
|
108
|
+
- An instance of the Pattern class.
|
|
109
|
+
|
|
110
|
+
Examples:
|
|
111
|
+
```
|
|
112
|
+
# Only matches a letter if not preceded by a digit.
|
|
113
|
+
my_pattern = s.merge(s.behind(s.digit()), s.letter())
|
|
114
|
+
```
|
|
118
115
|
"""
|
|
119
116
|
|
|
120
117
|
if isinstance(pattern, str):
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
1
|
import re, textwrap
|
|
3
2
|
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
############################
|
|
7
|
-
# Base Functions
|
|
8
|
-
########
|
|
9
|
-
|
|
10
4
|
class STRlingError(ValueError):
|
|
11
5
|
def __init__(self, message):
|
|
12
6
|
self.message = textwrap.dedent(message).strip().replace('\n', '\n\t')
|
|
@@ -21,7 +15,7 @@ def lit(text):
|
|
|
21
15
|
|
|
22
16
|
def repeat(min_rep: int = None, max_rep: int = None):
|
|
23
17
|
if min_rep is not None and max_rep is not None:
|
|
24
|
-
if max_rep == 0:
|
|
18
|
+
if max_rep == 0:
|
|
25
19
|
return f'{{{min_rep},}}'
|
|
26
20
|
if min_rep > max_rep:
|
|
27
21
|
message = """
|
|
@@ -45,13 +39,15 @@ class Pattern:
|
|
|
45
39
|
Attributes:
|
|
46
40
|
- pattern (str): The regex pattern as a string.
|
|
47
41
|
- custom_set (bool): Indicates if the pattern is a custom character set.
|
|
42
|
+
- negated (bool): Indicates if the pattern is a negated custom character set.
|
|
48
43
|
- composite (bool): Indicates if the pattern is a composite pattern.
|
|
49
|
-
-
|
|
44
|
+
- named_groups (list): Indicates the list of named groups within.
|
|
45
|
+
- numbered_group (bool): Indicates if the pattern is a numbered group.
|
|
50
46
|
|
|
51
47
|
Methods:
|
|
52
48
|
- __call__(min_rep=None, max_rep=None): Returns a new Pattern object with the repetition pattern applied.
|
|
53
49
|
- __str__(): Returns the pattern as a string.
|
|
54
|
-
-
|
|
50
|
+
- create_modified_instance(): Returns an independent copy of the pattern instance.
|
|
55
51
|
"""
|
|
56
52
|
def __init__(self, pattern: str, custom_set: bool = False, negated: bool = False, composite: bool = False, named_groups: list = [], numbered_group: bool = False):
|
|
57
53
|
# The regex pattern string for this instance.
|
|
@@ -73,11 +69,7 @@ class Pattern:
|
|
|
73
69
|
|
|
74
70
|
Parameters: (min_rep/exact_rep, max_rep)
|
|
75
71
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
76
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
77
|
-
|
|
78
|
-
Special Cases:
|
|
79
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
80
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
72
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
81
73
|
|
|
82
74
|
Returns:
|
|
83
75
|
- A new Pattern object with the repetition pattern applied.
|
|
@@ -139,7 +131,7 @@ class Pattern:
|
|
|
139
131
|
"""
|
|
140
132
|
raise STRlingError(message)
|
|
141
133
|
|
|
142
|
-
#
|
|
134
|
+
# A numbered group repeats by copying, not amending a range.
|
|
143
135
|
if self.numbered_group:
|
|
144
136
|
if max_rep is not None:
|
|
145
137
|
message = """
|
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
|
|
2
1
|
from .pattern import STRlingError, Pattern, lit
|
|
3
2
|
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
############################
|
|
7
|
-
# User Char Sets
|
|
8
|
-
########
|
|
9
|
-
|
|
10
|
-
|
|
11
4
|
def between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
12
5
|
"""
|
|
13
|
-
Matches all characters within and including the start and end of a letter or
|
|
14
|
-
|
|
15
|
-
Examples:
|
|
16
|
-
- Matches any digit from 0 to 9.
|
|
17
|
-
|
|
18
|
-
my_pattern1 = s.between(0, 9)
|
|
19
|
-
|
|
20
|
-
- Matches any lowercase letter from 'a' to 'z'.
|
|
21
|
-
|
|
22
|
-
my_pattern2 = s.between('a', 'z')
|
|
23
|
-
|
|
24
|
-
- Matches any uppercase letter from 'A' to 'Z'.
|
|
25
|
-
|
|
26
|
-
my_pattern3 = s.between('A', 'Z')
|
|
6
|
+
Matches all characters within and including the start and end of a letter or digit range.
|
|
27
7
|
|
|
28
8
|
Parameters:
|
|
29
9
|
- start (str or int): The starting character or digit of the range.
|
|
@@ -32,14 +12,26 @@ def between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
|
32
12
|
- max_rep (optional): Specifies the maximum digit of characters to match.
|
|
33
13
|
|
|
34
14
|
Returns:
|
|
35
|
-
-
|
|
15
|
+
- An instance of the Pattern class.
|
|
16
|
+
|
|
17
|
+
Examples:
|
|
18
|
+
```
|
|
19
|
+
# Matches any digit from 0 to 9.
|
|
20
|
+
my_pattern1 = s.between(0, 9)
|
|
21
|
+
|
|
22
|
+
# Matches any lowercase letter from 'a' to 'z'.
|
|
23
|
+
my_pattern2 = s.between('a', 'z')
|
|
24
|
+
|
|
25
|
+
# Matches any uppercase letter from 'A' to 'Z'.
|
|
26
|
+
my_pattern3 = s.between('A', 'Z')
|
|
27
|
+
```
|
|
36
28
|
"""
|
|
37
29
|
|
|
38
30
|
if not (isinstance(start, str) and isinstance(end, str)) and not (isinstance(start, int) and isinstance(end, int)):
|
|
39
31
|
message = """
|
|
40
32
|
Method: simply.between(start, end)
|
|
41
33
|
|
|
42
|
-
The
|
|
34
|
+
The 'start' and 'end' arguments must both be integers (0-9) or letters of the same case (A-Z or a-z).
|
|
43
35
|
"""
|
|
44
36
|
raise STRlingError(message)
|
|
45
37
|
|
|
@@ -48,7 +40,7 @@ def between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
|
48
40
|
message = """
|
|
49
41
|
Method: simply.between(start, end)
|
|
50
42
|
|
|
51
|
-
The
|
|
43
|
+
The 'start' integer must not be greater than the 'end' integer.
|
|
52
44
|
"""
|
|
53
45
|
raise STRlingError(message)
|
|
54
46
|
|
|
@@ -56,7 +48,7 @@ def between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
|
56
48
|
message = """
|
|
57
49
|
Method: simply.between(start, end)
|
|
58
50
|
|
|
59
|
-
The
|
|
51
|
+
The 'start' and 'end' integers must be single digits (0-9).
|
|
60
52
|
"""
|
|
61
53
|
raise STRlingError(message)
|
|
62
54
|
|
|
@@ -67,7 +59,7 @@ def between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
|
67
59
|
message = """
|
|
68
60
|
Method: simply.between(start, end)
|
|
69
61
|
|
|
70
|
-
The
|
|
62
|
+
The 'start' and 'end' must be alphabetical characters.
|
|
71
63
|
"""
|
|
72
64
|
raise STRlingError(message)
|
|
73
65
|
|
|
@@ -75,7 +67,7 @@ def between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
|
75
67
|
message = """
|
|
76
68
|
Method: simply.between(start, end)
|
|
77
69
|
|
|
78
|
-
The
|
|
70
|
+
The 'start' and 'end' characters must be single letters.
|
|
79
71
|
"""
|
|
80
72
|
raise STRlingError(message)
|
|
81
73
|
|
|
@@ -83,7 +75,7 @@ def between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
|
83
75
|
message = """
|
|
84
76
|
Method: simply.between(start, end)
|
|
85
77
|
|
|
86
|
-
The
|
|
78
|
+
The 'start' and 'end' characters must be of the same case.
|
|
87
79
|
"""
|
|
88
80
|
raise STRlingError(message)
|
|
89
81
|
|
|
@@ -91,7 +83,7 @@ def between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
|
91
83
|
message = """
|
|
92
84
|
Method: simply.between(start, end)
|
|
93
85
|
|
|
94
|
-
The
|
|
86
|
+
The 'start' character must not be lexicographically greater than the 'end' character.
|
|
95
87
|
"""
|
|
96
88
|
raise STRlingError(message)
|
|
97
89
|
|
|
@@ -104,19 +96,6 @@ def not_between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
|
104
96
|
"""
|
|
105
97
|
Matches any character not within or including the start and end of a letter or digit range.
|
|
106
98
|
|
|
107
|
-
Examples:
|
|
108
|
-
- Matches any character that is not a digit from 0 to 9.
|
|
109
|
-
|
|
110
|
-
my_pattern1 = s.not_between(0, 9)
|
|
111
|
-
|
|
112
|
-
- Matches any character that is not a lowercase letter from 'a' to 'z'.
|
|
113
|
-
|
|
114
|
-
my_pattern2 = s.not_between('a', 'z')
|
|
115
|
-
|
|
116
|
-
- Matches any character that is not a uppercase letter from 'A' to 'Z'.
|
|
117
|
-
|
|
118
|
-
my_pattern3 = s.not_between('A', 'Z')
|
|
119
|
-
|
|
120
99
|
Parameters:
|
|
121
100
|
- start (str or int): The starting character or digit of the range.
|
|
122
101
|
- end (str or int): The ending character or digit of the range.
|
|
@@ -124,14 +103,26 @@ def not_between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
|
124
103
|
- max_rep (optional): Specifies the maximum digit of characters to match.
|
|
125
104
|
|
|
126
105
|
Returns:
|
|
127
|
-
-
|
|
106
|
+
- An instance of the Pattern class.
|
|
107
|
+
|
|
108
|
+
Examples:
|
|
109
|
+
```
|
|
110
|
+
# Matches any character that is not a digit from 0 to 9.
|
|
111
|
+
my_pattern1 = s.not_between(0, 9)
|
|
112
|
+
|
|
113
|
+
# Matches any character that is not a lowercase letter from 'a' to 'z'.
|
|
114
|
+
my_pattern2 = s.not_between('a', 'z')
|
|
115
|
+
|
|
116
|
+
# Matches any character that is not a uppercase letter from 'A' to 'Z'.
|
|
117
|
+
my_pattern3 = s.not_between('A', 'Z')
|
|
118
|
+
```
|
|
128
119
|
"""
|
|
129
120
|
|
|
130
121
|
if not (isinstance(start, str) and isinstance(end, str)) and not (isinstance(start, int) and isinstance(end, int)):
|
|
131
122
|
message = """
|
|
132
123
|
Method: simply.not_between(start, end)
|
|
133
124
|
|
|
134
|
-
The
|
|
125
|
+
The 'start' and 'end' arguments must both be integers (0-9) or letters of the same case (A-Z or a-z).
|
|
135
126
|
"""
|
|
136
127
|
raise STRlingError(message)
|
|
137
128
|
|
|
@@ -140,7 +131,7 @@ def not_between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
|
140
131
|
message = """
|
|
141
132
|
Method: simply.not_between(start, end)
|
|
142
133
|
|
|
143
|
-
The
|
|
134
|
+
The 'start' integer must not be greater than the 'end' integer.
|
|
144
135
|
"""
|
|
145
136
|
raise STRlingError(message)
|
|
146
137
|
|
|
@@ -148,7 +139,7 @@ def not_between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
|
148
139
|
message = """
|
|
149
140
|
Method: simply.not_between(start, end)
|
|
150
141
|
|
|
151
|
-
The
|
|
142
|
+
The 'start' and 'end' integers must be single digits (0-9).
|
|
152
143
|
"""
|
|
153
144
|
raise STRlingError(message)
|
|
154
145
|
|
|
@@ -159,7 +150,7 @@ def not_between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
|
159
150
|
message = """
|
|
160
151
|
Method: simply.not_between(start, end)
|
|
161
152
|
|
|
162
|
-
The
|
|
153
|
+
The 'start' and 'end' must be alphabetical characters.
|
|
163
154
|
"""
|
|
164
155
|
raise STRlingError(message)
|
|
165
156
|
|
|
@@ -167,7 +158,7 @@ def not_between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
|
167
158
|
message = """
|
|
168
159
|
Method: simply.not_between(start, end)
|
|
169
160
|
|
|
170
|
-
The
|
|
161
|
+
The 'start' and 'end' characters must be single letters.
|
|
171
162
|
"""
|
|
172
163
|
raise STRlingError(message)
|
|
173
164
|
|
|
@@ -175,7 +166,7 @@ def not_between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
|
175
166
|
message = """
|
|
176
167
|
Method: simply.not_between(start, end)
|
|
177
168
|
|
|
178
|
-
The
|
|
169
|
+
The 'start' and 'end' characters must be of the same case.
|
|
179
170
|
"""
|
|
180
171
|
raise STRlingError(message)
|
|
181
172
|
|
|
@@ -183,7 +174,7 @@ def not_between(start: str, end: str, min_rep: int = None, max_rep: int = None):
|
|
|
183
174
|
message = """
|
|
184
175
|
Method: simply.not_between(start, end)
|
|
185
176
|
|
|
186
|
-
The
|
|
177
|
+
The 'start' character must not be lexicographically greater than the 'end' character.
|
|
187
178
|
"""
|
|
188
179
|
raise STRlingError(message)
|
|
189
180
|
|
|
@@ -196,16 +187,17 @@ def in_chars(*patterns):
|
|
|
196
187
|
"""
|
|
197
188
|
Matches any provided patterns, but they can't include subpatterns.
|
|
198
189
|
|
|
199
|
-
Example:
|
|
200
|
-
- Matches any letter, digit, comma, and period.
|
|
201
|
-
|
|
202
|
-
my_pattern = s.in_chars(s.letter(), s.digit(), ',.')
|
|
203
|
-
|
|
204
190
|
Parameters:
|
|
205
191
|
- patterns (Pattern/str): One or more non-composite patterns to match.
|
|
206
192
|
|
|
207
193
|
Returns:
|
|
208
|
-
-
|
|
194
|
+
- An instance of the Pattern class.
|
|
195
|
+
|
|
196
|
+
Examples:
|
|
197
|
+
```
|
|
198
|
+
# Matches any letter, digit, comma, and period.
|
|
199
|
+
my_pattern = s.in_chars(s.letter(), s.digit(), ',.')
|
|
200
|
+
```
|
|
209
201
|
"""
|
|
210
202
|
|
|
211
203
|
# Check all patterns are instance of Pattern or str
|
|
@@ -255,7 +247,7 @@ def in_chars(*patterns):
|
|
|
255
247
|
"""
|
|
256
248
|
raise STRlingError(message)
|
|
257
249
|
else:
|
|
258
|
-
joined += str(pattern)[1:-1] # [
|
|
250
|
+
joined += str(pattern)[1:-1] # [chars] => chars
|
|
259
251
|
else:
|
|
260
252
|
joined += str(pattern)
|
|
261
253
|
|
|
@@ -266,20 +258,17 @@ def not_in_chars(*patterns):
|
|
|
266
258
|
"""
|
|
267
259
|
Matches anything but the provided patterns, but they can't include subpatterns.
|
|
268
260
|
|
|
269
|
-
Example:
|
|
270
|
-
|
|
271
|
-
- Matches any character that is not a letter, digit, comma, and period.
|
|
272
|
-
|
|
273
|
-
my_pattern = s.not_in_chars(s.letter(), s.digit(), ',.')
|
|
274
|
-
|
|
275
261
|
Parameters:
|
|
276
262
|
- patterns (Pattern/str): One or more non-composite patterns to avoid.
|
|
277
263
|
|
|
278
|
-
Note: A composite pattern is one consisting of subpatterns,
|
|
279
|
-
they are created by constructors and lookarounds.
|
|
280
|
-
|
|
281
264
|
Returns:
|
|
282
|
-
-
|
|
265
|
+
- An instance of the Pattern class.
|
|
266
|
+
|
|
267
|
+
Examples:
|
|
268
|
+
```
|
|
269
|
+
# Matches any character that is not a letter, digit, comma, and period.
|
|
270
|
+
my_pattern = s.not_in_chars(s.letter(), s.digit(), ',.')
|
|
271
|
+
```
|
|
283
272
|
"""
|
|
284
273
|
|
|
285
274
|
# Check all patterns are instance of Pattern or str
|
|
@@ -320,9 +309,9 @@ def not_in_chars(*patterns):
|
|
|
320
309
|
|
|
321
310
|
if pattern.custom_set:
|
|
322
311
|
if pattern.negated:
|
|
323
|
-
joined += str(pattern)[2:-1] # [^
|
|
312
|
+
joined += str(pattern)[2:-1] # [^chars] => chars
|
|
324
313
|
else:
|
|
325
|
-
joined += str(pattern)[1:-1] # [
|
|
314
|
+
joined += str(pattern)[1:-1] # [chars] => chars
|
|
326
315
|
else:
|
|
327
316
|
joined += str(pattern)
|
|
328
317
|
|
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
|
|
2
1
|
from .pattern import Pattern, lit
|
|
3
2
|
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
############################
|
|
7
|
-
# Custom Char Sets
|
|
8
|
-
########
|
|
9
|
-
|
|
10
|
-
|
|
11
4
|
def alpha_num(min_rep: int = None, max_rep: int = None):
|
|
12
5
|
"""
|
|
13
6
|
Matches any letter (uppercase or lowercase) or digit.
|
|
14
7
|
|
|
15
|
-
Parameters: (min_rep
|
|
8
|
+
Parameters: (min_rep, max_rep)
|
|
16
9
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
17
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
18
|
-
|
|
19
|
-
Special Cases:
|
|
20
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
21
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
10
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
22
11
|
|
|
23
12
|
Returns:
|
|
24
13
|
- An instance of the Pattern class.
|
|
@@ -30,13 +19,9 @@ def not_alpha_num(min_rep: int = None, max_rep: int = None):
|
|
|
30
19
|
"""
|
|
31
20
|
Matches any character that is not a letter or digit.
|
|
32
21
|
|
|
33
|
-
Parameters: (min_rep
|
|
22
|
+
Parameters: (min_rep, max_rep)
|
|
34
23
|
- 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.
|
|
24
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
40
25
|
|
|
41
26
|
Returns:
|
|
42
27
|
- An instance of the Pattern class.
|
|
@@ -48,13 +33,9 @@ def special_char(min_rep: int = None, max_rep: int = None):
|
|
|
48
33
|
"""
|
|
49
34
|
Matches any special character. => !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
|
|
50
35
|
|
|
51
|
-
Parameters: (min_rep
|
|
36
|
+
Parameters: (min_rep, max_rep)
|
|
52
37
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
53
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
54
|
-
|
|
55
|
-
Special Cases:
|
|
56
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
57
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
38
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
58
39
|
|
|
59
40
|
Returns:
|
|
60
41
|
- An instance of the Pattern class.
|
|
@@ -67,13 +48,9 @@ def not_special_char(min_rep: int = None, max_rep: int = None):
|
|
|
67
48
|
"""
|
|
68
49
|
Matches anything but a special character. => !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
|
|
69
50
|
|
|
70
|
-
Parameters: (min_rep
|
|
51
|
+
Parameters: (min_rep, max_rep)
|
|
71
52
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
72
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
73
|
-
|
|
74
|
-
Special Cases:
|
|
75
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
76
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
53
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
77
54
|
|
|
78
55
|
Returns:
|
|
79
56
|
- An instance of the Pattern class.
|
|
@@ -86,13 +63,9 @@ def letter(min_rep: int = None, max_rep: int = None):
|
|
|
86
63
|
"""
|
|
87
64
|
Matches any letter (uppercase or lowercase).
|
|
88
65
|
|
|
89
|
-
Parameters: (min_rep
|
|
66
|
+
Parameters: (min_rep, max_rep)
|
|
90
67
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
91
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
92
|
-
|
|
93
|
-
Special Cases:
|
|
94
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
95
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
68
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
96
69
|
|
|
97
70
|
Returns:
|
|
98
71
|
- An instance of the Pattern class.
|
|
@@ -104,13 +77,9 @@ def not_letter(min_rep: int = None, max_rep: int = None):
|
|
|
104
77
|
"""
|
|
105
78
|
Matches any character that is not a letter.
|
|
106
79
|
|
|
107
|
-
Parameters: (min_rep
|
|
80
|
+
Parameters: (min_rep, max_rep)
|
|
108
81
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
109
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
110
|
-
|
|
111
|
-
Special Cases:
|
|
112
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
113
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
82
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
114
83
|
|
|
115
84
|
Returns:
|
|
116
85
|
- An instance of the Pattern class.
|
|
@@ -122,13 +91,9 @@ def upper(min_rep: int = None, max_rep: int = None):
|
|
|
122
91
|
"""
|
|
123
92
|
Matches any uppercase letter.
|
|
124
93
|
|
|
125
|
-
Parameters: (min_rep
|
|
94
|
+
Parameters: (min_rep, max_rep)
|
|
126
95
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
127
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
128
|
-
|
|
129
|
-
Special Cases:
|
|
130
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
131
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
96
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
132
97
|
|
|
133
98
|
Returns:
|
|
134
99
|
- An instance of the Pattern class.
|
|
@@ -140,13 +105,9 @@ def not_upper(min_rep: int = None, max_rep: int = None):
|
|
|
140
105
|
"""
|
|
141
106
|
Matches any character that is not an uppercase letter.
|
|
142
107
|
|
|
143
|
-
Parameters: (min_rep
|
|
108
|
+
Parameters: (min_rep, max_rep)
|
|
144
109
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
145
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
146
|
-
|
|
147
|
-
Special Cases:
|
|
148
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
149
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
110
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
150
111
|
|
|
151
112
|
Returns:
|
|
152
113
|
- An instance of the Pattern class.
|
|
@@ -158,13 +119,9 @@ def lower(min_rep: int = None, max_rep: int = None):
|
|
|
158
119
|
"""
|
|
159
120
|
Matches any lowercase letter.
|
|
160
121
|
|
|
161
|
-
Parameters: (min_rep
|
|
122
|
+
Parameters: (min_rep, max_rep)
|
|
162
123
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
163
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
164
|
-
|
|
165
|
-
Special Cases:
|
|
166
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
167
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
124
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
168
125
|
|
|
169
126
|
Returns:
|
|
170
127
|
- An instance of the Pattern class.
|
|
@@ -176,13 +133,9 @@ def not_lower(min_rep: int = None, max_rep: int = None):
|
|
|
176
133
|
"""
|
|
177
134
|
Matches any character that is not a lowercase letter.
|
|
178
135
|
|
|
179
|
-
Parameters: (min_rep
|
|
136
|
+
Parameters: (min_rep, max_rep)
|
|
180
137
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
181
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
182
|
-
|
|
183
|
-
Special Cases:
|
|
184
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
185
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
138
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
186
139
|
|
|
187
140
|
Returns:
|
|
188
141
|
- An instance of the Pattern class.
|
|
@@ -195,13 +148,9 @@ def hex_digit(min_rep: int = None, max_rep: int = None):
|
|
|
195
148
|
Matches any hex-digit character.
|
|
196
149
|
A hex-digit character is any letter A through F (uppercase or lowercase) or any digit (0-9).
|
|
197
150
|
|
|
198
|
-
Parameters: (min_rep
|
|
151
|
+
Parameters: (min_rep, max_rep)
|
|
199
152
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
200
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
201
|
-
|
|
202
|
-
Special Cases:
|
|
203
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
204
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
153
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
205
154
|
|
|
206
155
|
Returns:
|
|
207
156
|
- An instance of the Pattern class.
|
|
@@ -214,13 +163,9 @@ def not_hex_digit(min_rep: int = None, max_rep: int = None):
|
|
|
214
163
|
Matches anything but a hex-digit character.
|
|
215
164
|
A hex-digit character is any letter A through F (uppercase or lowercase) or any digit (0-9).
|
|
216
165
|
|
|
217
|
-
Parameters: (min_rep
|
|
166
|
+
Parameters: (min_rep, max_rep)
|
|
218
167
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
219
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
220
|
-
|
|
221
|
-
Special Cases:
|
|
222
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
223
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
168
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
224
169
|
|
|
225
170
|
Returns:
|
|
226
171
|
- An instance of the Pattern class.
|
|
@@ -238,13 +183,9 @@ def digit(min_rep: int = None, max_rep: int = None):
|
|
|
238
183
|
"""
|
|
239
184
|
Matches any digit.
|
|
240
185
|
|
|
241
|
-
Parameters: (min_rep
|
|
186
|
+
Parameters: (min_rep, max_rep)
|
|
242
187
|
- 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.
|
|
188
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
248
189
|
|
|
249
190
|
Returns:
|
|
250
191
|
- An instance of the Pattern class.
|
|
@@ -256,13 +197,9 @@ def not_digit(min_rep: int = None, max_rep: int = None):
|
|
|
256
197
|
"""
|
|
257
198
|
Matches any character that is not a digit.
|
|
258
199
|
|
|
259
|
-
Parameters: (min_rep
|
|
200
|
+
Parameters: (min_rep, max_rep)
|
|
260
201
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
261
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
262
|
-
|
|
263
|
-
Special Cases:
|
|
264
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
265
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
202
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
266
203
|
|
|
267
204
|
Returns:
|
|
268
205
|
- An instance of the Pattern class.
|
|
@@ -274,13 +211,9 @@ def whitespace(min_rep: int = None, max_rep: int = None):
|
|
|
274
211
|
"""
|
|
275
212
|
Matches any whitespace character. (Whitespaces include space, tab, newline, carriage return, etc.)
|
|
276
213
|
|
|
277
|
-
Parameters: (min_rep
|
|
214
|
+
Parameters: (min_rep, max_rep)
|
|
278
215
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
279
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
280
|
-
|
|
281
|
-
Special Cases:
|
|
282
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
283
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
216
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
284
217
|
|
|
285
218
|
Returns:
|
|
286
219
|
- An instance of the Pattern class.
|
|
@@ -292,13 +225,9 @@ def not_whitespace(min_rep: int = None, max_rep: int = None):
|
|
|
292
225
|
"""
|
|
293
226
|
Matches any character that is not a whitespace character. (Whitespaces include space, tab, newline, carriage return, etc.)
|
|
294
227
|
|
|
295
|
-
Parameters: (min_rep
|
|
228
|
+
Parameters: (min_rep, max_rep)
|
|
296
229
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
297
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
298
|
-
|
|
299
|
-
Special Cases:
|
|
300
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
301
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
230
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
302
231
|
|
|
303
232
|
Returns:
|
|
304
233
|
- An instance of the Pattern class.
|
|
@@ -310,13 +239,9 @@ def newline(min_rep: int = None, max_rep: int = None):
|
|
|
310
239
|
"""
|
|
311
240
|
Matches a newline character.
|
|
312
241
|
|
|
313
|
-
Parameters: (min_rep
|
|
242
|
+
Parameters: (min_rep, max_rep)
|
|
314
243
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
315
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
316
|
-
|
|
317
|
-
Special Cases:
|
|
318
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
319
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
244
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
320
245
|
|
|
321
246
|
Returns:
|
|
322
247
|
- An instance of the Pattern class.
|
|
@@ -328,13 +253,9 @@ def not_newline(min_rep: int = None, max_rep: int = None):
|
|
|
328
253
|
"""
|
|
329
254
|
Matches any character that is not a newline.
|
|
330
255
|
|
|
331
|
-
Parameters: (min_rep
|
|
256
|
+
Parameters: (min_rep, max_rep)
|
|
332
257
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
333
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
334
|
-
|
|
335
|
-
Special Cases:
|
|
336
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
337
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
258
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
338
259
|
|
|
339
260
|
Returns:
|
|
340
261
|
- An instance of the Pattern class.
|
|
@@ -346,13 +267,9 @@ def tab(min_rep: int = None, max_rep: int = None):
|
|
|
346
267
|
"""
|
|
347
268
|
Matches a tab character.
|
|
348
269
|
|
|
349
|
-
Parameters: (min_rep
|
|
270
|
+
Parameters: (min_rep, max_rep)
|
|
350
271
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
351
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
352
|
-
|
|
353
|
-
Special Cases:
|
|
354
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
355
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
272
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
356
273
|
|
|
357
274
|
Returns:
|
|
358
275
|
- An instance of the Pattern class.
|
|
@@ -364,13 +281,9 @@ def carriage(min_rep: int = None, max_rep: int = None):
|
|
|
364
281
|
"""
|
|
365
282
|
Matches a carriage return character.
|
|
366
283
|
|
|
367
|
-
Parameters: (min_rep
|
|
284
|
+
Parameters: (min_rep, max_rep)
|
|
368
285
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
369
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
370
|
-
|
|
371
|
-
Special Cases:
|
|
372
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
373
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
286
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
374
287
|
|
|
375
288
|
Returns:
|
|
376
289
|
- An instance of the Pattern class.
|
|
@@ -382,13 +295,9 @@ def bound(min_rep: int = None, max_rep: int = None):
|
|
|
382
295
|
"""
|
|
383
296
|
Matches a boundary character.
|
|
384
297
|
|
|
385
|
-
Parameters: (min_rep
|
|
298
|
+
Parameters: (min_rep, max_rep)
|
|
386
299
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
387
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
388
|
-
|
|
389
|
-
Special Cases:
|
|
390
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
391
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
300
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
392
301
|
|
|
393
302
|
Returns:
|
|
394
303
|
- An instance of the Pattern class.
|
|
@@ -400,13 +309,9 @@ def not_bound(min_rep: int = None, max_rep: int = None):
|
|
|
400
309
|
"""
|
|
401
310
|
Matches any character that is not a boundary.
|
|
402
311
|
|
|
403
|
-
Parameters: (min_rep
|
|
312
|
+
Parameters: (min_rep, max_rep)
|
|
404
313
|
- min_rep (optional): Specifies the minimum number of characters to match.
|
|
405
|
-
- max_rep (optional): Specifies the maximum number of characters to match.
|
|
406
|
-
|
|
407
|
-
Special Cases:
|
|
408
|
-
- If only `min_rep` is specified, it represents the exact number of characters to match.
|
|
409
|
-
- If `max_rep` is 0, it means there is no upper limit.
|
|
314
|
+
- max_rep (optional): Specifies the maximum number of characters to match, 0 means unlimited, None means match exact count of min_rep.
|
|
410
315
|
|
|
411
316
|
Returns:
|
|
412
317
|
- An instance of the Pattern class.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: STRling
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.4
|
|
4
4
|
Description-Content-Type: text/markdown
|
|
5
5
|
|
|
6
6
|
# STRling
|
|
@@ -99,18 +99,26 @@ for match in matches:
|
|
|
99
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
100
|
|
|
101
101
|
## 🌎 Locations
|
|
102
|
+
|
|
102
103
|
### STRling for Python
|
|
104
|
+
|
|
103
105
|
[](https://pypi.org/project/STRling/)
|
|
104
106
|
[](https://github.com/TheCyberLocal/STRling-Py)
|
|
105
107
|
|
|
106
108
|
### STRling for JavaScript
|
|
107
|
-
|
|
109
|
+
|
|
110
|
+
[](https://www.npmjs.com/package/@thecyberlocal/strling)
|
|
108
111
|
[](https://github.com/TheCyberLocal/STRling-JS)
|
|
109
112
|
|
|
110
113
|
## 🌐 Socials
|
|
114
|
+
|
|
111
115
|
[](https://linkedin.com/in/tzm01)
|
|
116
|
+
[](https://github.com/TheCyberLocal)
|
|
117
|
+
[](https://pypi.org/user/TheCyberLocal/)
|
|
118
|
+
[](https://www.npmjs.com/~thecyberlocal)
|
|
112
119
|
|
|
113
120
|
## 💖 Support
|
|
121
|
+
|
|
114
122
|
If you find my content helpful or interesting, consider buying me a coffee. Every cup is greatly appreciated and fuels my work!
|
|
115
123
|
|
|
116
124
|
[](https://buymeacoffee.com/thecyberlocal)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|