V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
soasme
V2EX  ›  Python

Simple Regex for Python

  •  
  •   soasme · 2016-09-08 16:17:06 +08:00 · 2102 次点击
    这是一个创建于 2788 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近为 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 可以熟练使用了,切换到正常的正则表达式来写自己的规则是很平滑容易的。

    5 条回复    2016-09-09 15:35:43 +08:00
    loading
        1
    loading  
       2016-09-08 20:02:41 +08:00 via Android
    正则,慢慢写还可以,给我看……头大
    21grams
        2
    21grams  
       2016-09-08 20:04:52 +08:00 via Android
    自带的还不够 simple 吗
    xuboying
        3
    xuboying  
       2016-09-09 00:15:56 +08:00 via Android
    自带的已经够简洁了,你自创文档写全了么?
    soasme
        4
    soasme  
    OP
       2016-09-09 15:34:47 +08:00
    soasme
        5
    soasme  
    OP
       2016-09-09 15:35:43 +08:00
    @loading 你可以试试看 SRL 。你可能仍然需要慢慢写,但是看起来不会头大。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1128 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 23:28 · PVG 07:28 · LAX 16:28 · JFK 19:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.