STRling 0.0.2__tar.gz → 0.0.3__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.
Potentially problematic release.
This version of STRling might be problematic. Click here for more details.
- {strling-0.0.2 → strling-0.0.3}/PKG-INFO +20 -14
- {strling-0.0.2 → strling-0.0.3}/README.md +19 -13
- strling-0.0.3/STRling/__init__.py +2 -0
- {strling-0.0.2 → strling-0.0.3}/STRling/lib.py +49 -28
- {strling-0.0.2 → strling-0.0.3}/STRling.egg-info/PKG-INFO +20 -14
- {strling-0.0.2 → strling-0.0.3}/setup.py +1 -1
- strling-0.0.2/STRling/__init__.py +0 -1
- {strling-0.0.2 → strling-0.0.3}/STRling.egg-info/SOURCES.txt +0 -0
- {strling-0.0.2 → strling-0.0.3}/STRling.egg-info/dependency_links.txt +0 -0
- {strling-0.0.2 → strling-0.0.3}/STRling.egg-info/top_level.txt +0 -0
- {strling-0.0.2 → strling-0.0.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: STRling
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.3
|
|
4
4
|
Description-Content-Type: text/markdown
|
|
5
5
|
|
|
6
6
|
# STRling
|
|
@@ -38,28 +38,34 @@ pip install STRling
|
|
|
38
38
|
Here's a quick example to demonstrate how easy it is to get started with STRling:
|
|
39
39
|
|
|
40
40
|
```python
|
|
41
|
-
from STRling import match, group, lib, test
|
|
42
41
|
import re
|
|
42
|
+
from STRling import digit, lit, group, merge, or_
|
|
43
43
|
|
|
44
|
-
# Define a
|
|
45
|
-
|
|
44
|
+
# Define a named capture group for phone number
|
|
45
|
+
first_group = group('first', digit()(3))
|
|
46
|
+
second_group = group('second', digit()(3))
|
|
47
|
+
third_group = group('third', digit()(4))
|
|
46
48
|
|
|
47
|
-
#
|
|
48
|
-
|
|
49
|
+
# Create a non-capturing group for phone number pattern
|
|
50
|
+
phone_num = merge(first_group, lit('-')(), second_group, lit('-')(), third_group)
|
|
49
51
|
|
|
50
|
-
# Create a
|
|
51
|
-
custom =
|
|
52
|
+
# Create a phone number group of 10 digits or the phone number pattern
|
|
53
|
+
custom = digit()(10)
|
|
54
|
+
phone_number = group('phone_number', or_(custom, phone_num))
|
|
52
55
|
|
|
53
|
-
#
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
# Create a phone number group using either custom or num10
|
|
57
|
-
phone_number = group('phone_number', lib.or_(custom, num10))
|
|
56
|
+
# Print the pattern value
|
|
57
|
+
print(str(phone_number))
|
|
58
|
+
# Output: (?P<phone_number>\d{10}|(?:(?P<first>\d{3})-(?P<second>\d{3})-(?P<third>\d{4})))
|
|
58
59
|
|
|
59
60
|
# Compile the pattern and match against a string
|
|
60
|
-
compiled_pattern = re.compile(phone_number)
|
|
61
|
+
compiled_pattern = re.compile(str(phone_number))
|
|
61
62
|
input_string = "123-456-7890"
|
|
62
63
|
match = compiled_pattern.match(input_string)
|
|
64
|
+
|
|
65
|
+
# Check the match and print the captured groups
|
|
66
|
+
if match:
|
|
67
|
+
print(match.groupdict())
|
|
68
|
+
# Output: {'phone_number': '123-456-7890', 'first': '123', 'second': '456', 'third': '7890'}
|
|
63
69
|
```
|
|
64
70
|
|
|
65
71
|
### License
|
|
@@ -33,28 +33,34 @@ pip install STRling
|
|
|
33
33
|
Here's a quick example to demonstrate how easy it is to get started with STRling:
|
|
34
34
|
|
|
35
35
|
```python
|
|
36
|
-
from STRling import match, group, lib, test
|
|
37
36
|
import re
|
|
37
|
+
from STRling import digit, lit, group, merge, or_
|
|
38
38
|
|
|
39
|
-
# Define a
|
|
40
|
-
|
|
39
|
+
# Define a named capture group for phone number
|
|
40
|
+
first_group = group('first', digit()(3))
|
|
41
|
+
second_group = group('second', digit()(3))
|
|
42
|
+
third_group = group('third', digit()(4))
|
|
41
43
|
|
|
42
|
-
#
|
|
43
|
-
|
|
44
|
+
# Create a non-capturing group for phone number pattern
|
|
45
|
+
phone_num = merge(first_group, lit('-')(), second_group, lit('-')(), third_group)
|
|
44
46
|
|
|
45
|
-
# Create a
|
|
46
|
-
custom =
|
|
47
|
+
# Create a phone number group of 10 digits or the phone number pattern
|
|
48
|
+
custom = digit()(10)
|
|
49
|
+
phone_number = group('phone_number', or_(custom, phone_num))
|
|
47
50
|
|
|
48
|
-
#
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
# Create a phone number group using either custom or num10
|
|
52
|
-
phone_number = group('phone_number', lib.or_(custom, num10))
|
|
51
|
+
# Print the pattern value
|
|
52
|
+
print(str(phone_number))
|
|
53
|
+
# Output: (?P<phone_number>\d{10}|(?:(?P<first>\d{3})-(?P<second>\d{3})-(?P<third>\d{4})))
|
|
53
54
|
|
|
54
55
|
# Compile the pattern and match against a string
|
|
55
|
-
compiled_pattern = re.compile(phone_number)
|
|
56
|
+
compiled_pattern = re.compile(str(phone_number))
|
|
56
57
|
input_string = "123-456-7890"
|
|
57
58
|
match = compiled_pattern.match(input_string)
|
|
59
|
+
|
|
60
|
+
# Check the match and print the captured groups
|
|
61
|
+
if match:
|
|
62
|
+
print(match.groupdict())
|
|
63
|
+
# Output: {'phone_number': '123-456-7890', 'first': '123', 'second': '456', 'third': '7890'}
|
|
58
64
|
```
|
|
59
65
|
|
|
60
66
|
### License
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
import re
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
# Decorators
|
|
5
|
-
def repetition(func):
|
|
6
|
-
def wrapper(*args, min=None, max=None, **kwargs):
|
|
7
|
-
pattern = func(*args, **kwargs)
|
|
8
|
-
pattern += repeat(min, max)
|
|
9
|
-
return pattern
|
|
10
|
-
return wrapper
|
|
11
|
-
|
|
12
|
-
|
|
13
4
|
# Range syntax
|
|
14
5
|
def repeat(min=None, max=None):
|
|
15
|
-
"""Create a range for the preceding symbol"""
|
|
6
|
+
"""Create a range for the preceding symbol."""
|
|
16
7
|
if min is not None and max is not None:
|
|
17
8
|
if min > max:
|
|
18
9
|
raise ValueError('min cannot be greater than max')
|
|
@@ -22,22 +13,52 @@ def repeat(min=None, max=None):
|
|
|
22
13
|
return ''
|
|
23
14
|
|
|
24
15
|
|
|
16
|
+
# Pattern class
|
|
17
|
+
class Pattern:
|
|
18
|
+
def __init__(self, pattern):
|
|
19
|
+
self.pattern = pattern
|
|
20
|
+
|
|
21
|
+
def __call__(self, min=None, max=None):
|
|
22
|
+
return self.pattern + repeat(min, max)
|
|
23
|
+
|
|
24
|
+
def __str__(self):
|
|
25
|
+
return self.pattern
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# Decorators
|
|
29
|
+
def repetition(func):
|
|
30
|
+
def wrapper(*args, **kwargs):
|
|
31
|
+
pattern = func(*args, **kwargs)
|
|
32
|
+
return Pattern(pattern)
|
|
33
|
+
return wrapper
|
|
34
|
+
|
|
35
|
+
|
|
25
36
|
# Literals
|
|
26
37
|
@repetition
|
|
27
38
|
def lit(text):
|
|
28
|
-
"""Match the literal string `text
|
|
39
|
+
"""Match the literal string `text`."""
|
|
29
40
|
return re.escape(text)
|
|
30
41
|
|
|
31
42
|
@repetition
|
|
32
|
-
def digit(
|
|
33
|
-
"""Match a digit
|
|
43
|
+
def digit():
|
|
44
|
+
"""Match a digit."""
|
|
34
45
|
return r'\d'
|
|
35
46
|
|
|
36
47
|
@repetition
|
|
37
|
-
def letter(
|
|
48
|
+
def letter():
|
|
38
49
|
"""Match a letter."""
|
|
39
50
|
return r'[A-Za-z]'
|
|
40
51
|
|
|
52
|
+
@repetition
|
|
53
|
+
def upper():
|
|
54
|
+
"""Match a letter."""
|
|
55
|
+
return r'[A-Z]'
|
|
56
|
+
|
|
57
|
+
@repetition
|
|
58
|
+
def lower():
|
|
59
|
+
"""Match a letter."""
|
|
60
|
+
return r'[a-z]'
|
|
61
|
+
|
|
41
62
|
@repetition
|
|
42
63
|
def between(start_char, end_char):
|
|
43
64
|
"""Match any character between `start_char` and `end_char`."""
|
|
@@ -84,53 +105,53 @@ def carriage():
|
|
|
84
105
|
# Conditionals
|
|
85
106
|
def or_(*patterns):
|
|
86
107
|
"""Match any of the given patterns."""
|
|
87
|
-
joined = '|'.join(patterns)
|
|
88
|
-
return f'({joined})'
|
|
108
|
+
joined = '|'.join(str(p) for p in patterns)
|
|
109
|
+
return Pattern(f'({joined})')
|
|
89
110
|
|
|
90
111
|
def may(pattern):
|
|
91
112
|
"""Match zero or one occurrence of the pattern."""
|
|
92
|
-
return f'{pattern}?'
|
|
113
|
+
return Pattern(f'{pattern}?')
|
|
93
114
|
|
|
94
115
|
|
|
95
116
|
# Anchors
|
|
96
117
|
def start():
|
|
97
118
|
"""Match the start of the string."""
|
|
98
|
-
return r'^'
|
|
119
|
+
return Pattern(r'^')
|
|
99
120
|
|
|
100
121
|
def end():
|
|
101
122
|
"""Match the end of the string."""
|
|
102
|
-
return r'$'
|
|
123
|
+
return Pattern(r'$')
|
|
103
124
|
|
|
104
125
|
def bound(text):
|
|
105
126
|
"""Match the exact word `text`."""
|
|
106
|
-
return r'\b'
|
|
127
|
+
return Pattern(r'\b')
|
|
107
128
|
|
|
108
129
|
|
|
109
130
|
# Lookarounds
|
|
110
131
|
def ahead(pattern):
|
|
111
132
|
"""Match if the pattern matches ahead."""
|
|
112
|
-
return f'(?={pattern})'
|
|
133
|
+
return Pattern(f'(?={pattern})')
|
|
113
134
|
|
|
114
135
|
def behind(pattern):
|
|
115
136
|
"""Match if the pattern matches behind."""
|
|
116
|
-
return f'(?<={pattern})'
|
|
137
|
+
return Pattern(f'(?<={pattern})')
|
|
117
138
|
|
|
118
139
|
def notahead(pattern):
|
|
119
140
|
"""Match if the pattern does not match ahead."""
|
|
120
|
-
return f'(?!{pattern})'
|
|
141
|
+
return Pattern(f'(?!{pattern})')
|
|
121
142
|
|
|
122
143
|
def notbehind(pattern):
|
|
123
144
|
"""Match if the pattern does not match behind."""
|
|
124
|
-
return f'(?<!{pattern})'
|
|
145
|
+
return Pattern(f'(?<!{pattern})')
|
|
125
146
|
|
|
126
147
|
|
|
127
148
|
# Grouping
|
|
128
149
|
def group(name, *patterns):
|
|
129
150
|
"""Create a named capture group with the given patterns."""
|
|
130
|
-
joined = ''.join(patterns)
|
|
131
|
-
return f'(?P<{name}>{joined})'
|
|
151
|
+
joined = ''.join(str(p) for p in patterns)
|
|
152
|
+
return Pattern(f'(?P<{name}>{joined})')
|
|
132
153
|
|
|
133
154
|
def merge(*patterns):
|
|
134
155
|
"""Create a non-capturing group with the given patterns."""
|
|
135
|
-
joined = ''.join(patterns)
|
|
136
|
-
return f'(?:{joined})'
|
|
156
|
+
joined = ''.join(str(p) for p in patterns)
|
|
157
|
+
return Pattern(f'(?:{joined})')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: STRling
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.3
|
|
4
4
|
Description-Content-Type: text/markdown
|
|
5
5
|
|
|
6
6
|
# STRling
|
|
@@ -38,28 +38,34 @@ pip install STRling
|
|
|
38
38
|
Here's a quick example to demonstrate how easy it is to get started with STRling:
|
|
39
39
|
|
|
40
40
|
```python
|
|
41
|
-
from STRling import match, group, lib, test
|
|
42
41
|
import re
|
|
42
|
+
from STRling import digit, lit, group, merge, or_
|
|
43
43
|
|
|
44
|
-
# Define a
|
|
45
|
-
|
|
44
|
+
# Define a named capture group for phone number
|
|
45
|
+
first_group = group('first', digit()(3))
|
|
46
|
+
second_group = group('second', digit()(3))
|
|
47
|
+
third_group = group('third', digit()(4))
|
|
46
48
|
|
|
47
|
-
#
|
|
48
|
-
|
|
49
|
+
# Create a non-capturing group for phone number pattern
|
|
50
|
+
phone_num = merge(first_group, lit('-')(), second_group, lit('-')(), third_group)
|
|
49
51
|
|
|
50
|
-
# Create a
|
|
51
|
-
custom =
|
|
52
|
+
# Create a phone number group of 10 digits or the phone number pattern
|
|
53
|
+
custom = digit()(10)
|
|
54
|
+
phone_number = group('phone_number', or_(custom, phone_num))
|
|
52
55
|
|
|
53
|
-
#
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
# Create a phone number group using either custom or num10
|
|
57
|
-
phone_number = group('phone_number', lib.or_(custom, num10))
|
|
56
|
+
# Print the pattern value
|
|
57
|
+
print(str(phone_number))
|
|
58
|
+
# Output: (?P<phone_number>\d{10}|(?:(?P<first>\d{3})-(?P<second>\d{3})-(?P<third>\d{4})))
|
|
58
59
|
|
|
59
60
|
# Compile the pattern and match against a string
|
|
60
|
-
compiled_pattern = re.compile(phone_number)
|
|
61
|
+
compiled_pattern = re.compile(str(phone_number))
|
|
61
62
|
input_string = "123-456-7890"
|
|
62
63
|
match = compiled_pattern.match(input_string)
|
|
64
|
+
|
|
65
|
+
# Check the match and print the captured groups
|
|
66
|
+
if match:
|
|
67
|
+
print(match.groupdict())
|
|
68
|
+
# Output: {'phone_number': '123-456-7890', 'first': '123', 'second': '456', 'third': '7890'}
|
|
63
69
|
```
|
|
64
70
|
|
|
65
71
|
### License
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from . import lib
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|