|
18 | 18 |
|
19 | 19 | regex.search(r'(?P<date>\d{4}-\d{2}-\d{2}).*(?&date)', row)[0] |
20 | 20 |
|
21 | | -## Set start of matching portion with \K |
| 21 | +## Set the start of matching portion with \K |
22 | 22 |
|
23 | 23 | regex.sub(r'\b\w\K\w*\W*', '', 'sea eat car rat eel tea') |
24 | 24 |
|
25 | 25 | s = 'cat scatter cater scat concatenate catastrophic catapult duplicate' |
26 | 26 |
|
27 | | -regex.sub(r'(cat.*?){2}\Kcat', '[\g<0>]', s, count=1) |
| 27 | +regex.sub(r'(cat.*?){2}\Kcat', r'[\g<0>]', s, count=1) |
28 | 28 |
|
29 | | -regex.sub(r'(cat.*?){2}\Kcat', '[\g<0>]', s) |
| 29 | +regex.sub(r'(cat.*?){2}\Kcat', r'[\g<0>]', s) |
30 | 30 |
|
31 | 31 | row = '421,cat,2425,42,5,cat,6,6,42,61,6,6,6,6,4' |
32 | 32 |
|
|
115 | 115 |
|
116 | 116 | regex.findall(r'\((?:[^()]++|\([^()]++\))++\)', eqn2) |
117 | 117 |
|
118 | | -lvl2 = regex.compile(''' |
119 | | - \( #literal ( |
120 | | - (?: #start of non-capturing group |
121 | | - [^()]++ #non-parentheses characters |
122 | | - | #OR |
123 | | - \([^()]++\) #level-one RE |
124 | | - )++ #end of non-capturing group, 1 or more times |
125 | | - \) #literal ) |
| 118 | +lvl2 = regex.compile(r''' |
| 119 | + \( # literal ( |
| 120 | + (?: # start of non-capturing group |
| 121 | + [^()]++ # non-parentheses characters |
| 122 | + | # OR |
| 123 | + \([^()]++\) # level-one RE |
| 124 | + )++ # end of non-capturing group, 1 or more times |
| 125 | + \) # literal ) |
126 | 126 | ''', flags=regex.X) |
127 | 127 |
|
128 | 128 | lvl2.findall(eqn1) |
129 | 129 |
|
130 | 130 | lvl2.findall(eqn2) |
131 | 131 |
|
132 | | -lvln = regex.compile(''' |
133 | | - \( #literal ( |
134 | | - (?: #start of non-capturing group |
135 | | - [^()]++ #non-parentheses characters |
136 | | - | #OR |
137 | | - (?0) #recursive call |
138 | | - )++ #end of non-capturing group, 1 or more times |
139 | | - \) #literal ) |
| 132 | +lvln = regex.compile(r''' |
| 133 | + \( # literal ( |
| 134 | + (?: # start of non-capturing group |
| 135 | + [^()]++ # non-parentheses characters |
| 136 | + | # OR |
| 137 | + (?0) # recursive call |
| 138 | + )++ # end of non-capturing group, 1 or more times |
| 139 | + \) # literal ) |
140 | 140 | ''', flags=regex.X) |
141 | 141 |
|
142 | 142 | lvln.findall(eqn0) |
|
0 commit comments