Created
November 2, 2018 04:08
-
-
Save kwatch/b9856c4bee0fb9d3efc72b43b4a8a455 to your computer and use it in GitHub Desktop.
Python < 3.5では、正規表現中のグループ数が100を超えると、エラーが出て正規表現がコンパイルできない。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import re | |
arr = [] | |
for i in range(1, 40): | |
arr.append("^/api/x%02s/(?:\d+)($)" % i) | |
arr.append("^/api/x%02s/(?:\d+)/edit($)" % i) | |
arr.append("^/api/x%02s/(?:\d+)/comments($)" % i) | |
all_rexp= re.compile("|".join(arr)) #=> AssertionError | |
print(all_rexp.pattern) | |
""" | |
$ python --version | |
Python 3.4.3 | |
$ python3 hom.py | |
Traceback (most recent call last): | |
File "hom.py", line 10, in <module> | |
all_rexp= re.compile("|".join(arr)) #=> AssertionError | |
File "/opt/vs/python/3.4.3/lib/python3.4/re.py", line 223, in compile | |
return _compile(pattern, flags) | |
File "/opt/vs/python/3.4.3/lib/python3.4/re.py", line 294, in _compile | |
p = sre_compile.compile(pattern, flags) | |
File "/opt/vs/python/3.4.3/lib/python3.4/sre_compile.py", line 579, in compile | |
"sorry, but this version only supports 100 named groups" | |
AssertionError: sorry, but this version only supports 100 named groups | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment