最近为 Simple Regex Language 写了 Python 实现: https://github.com/SimpleRegex/SRL-Python
对 Python 刚入门的孩子,如果觉得正则表达式很难,不妨试一试使用这个库。可以使用 pip install srl 安装这个库。
比如:
from srl import SRL
srl = SRL('letter from a to f exactly 4 times')
srl.match('abcd') # <_sre.SRE_Match at 0x10f4d6718>
srl.match('abc') # False
更多规则可以查看 https://simple-regex.com/
如果 Simple Regex 可以熟练使用了,切换到正常的正则表达式来写自己的规则是很平滑容易的。