V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Sep 8, 2016 · 2726 views
    This topic created in 3518 days ago, the information mentioned may be changed or developed.

    最近为 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 replies    2016-09-09 15:35:43 +08:00
    loading
        1
    loading  
       Sep 8, 2016 via Android
    正则,慢慢写还可以,给我看……头大
    21grams
        2
    21grams  
       Sep 8, 2016 via Android
    自带的还不够 simple 吗
    xuboying
        3
    xuboying  
       Sep 9, 2016 via Android
    自带的已经够简洁了,你自创文档写全了么?
    soasme
        4
    soasme  
    OP
       Sep 9, 2016
    soasme
        5
    soasme  
    OP
       Sep 9, 2016
    @loading 你可以试试看 SRL 。你可能仍然需要慢慢写,但是看起来不会头大。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1022 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 19:02 · PVG 03:02 · LAX 12:02 · JFK 15:02
    ♥ Do have faith in what you're doing.