与正则表达式有关 sre_yield

码农软件 · 软件分类 · 网络工具包 · 2019-02-26 09:12:38

软件介绍

sre_yield 是用于生成正则表达式匹配结果的 Python 模块,并尽可能的匹配到所有有效值。它采用了解析正则表达式的方式,所以你可以得到一个更加精确的结果,而不仅仅只是分散的字符串。

sre_yield 通常都无法处理反向引用、lookarounds 正则表达式,除此之外,还有在这几种情况下也无法处理;

  • The maximum value for repeats is system-dependant -- CPython's sre module there's a special value which is treated as infinite (either 2**16-1 or 2**32-1 depending on build).  In sre_yield, this is taken as a literal, rather than infinite, thus (on a 2**16-1 platform):

  • The re module docs say "Regular expression pattern strings may not contain null bytes" yet this appears to work fine.

  • Order does not depend on greediness.

  • The regex is treated as fullmatch.

  • sre_yield is confused by even the simplest of anchors:

代码示例:

>>> import random
>>> v = sre_yield.AllStrings('[abc]{1,4}')
>>> len(v)
120

# Now random.choice(v) has a 3/120 chance of choosing a single letter.
>>> random.seed(1)
>>> sum([1 if len(random.choice(v)) == 1 else 0 for _ in range(120)])
3

# xeger(v) has ~25% chance of choosing a single letter, because the length
and match are chosen independently.
> from rstr import xeger
> sum([1 if len(xeger('[abc]{1,4}')) == 1 else 0 for _ in range(120)])
26


本文地址:https://www.codercto.com/soft/d/157.html

Android编程权威指南(第3版)

Android编程权威指南(第3版)

比尔·菲利普斯 (Bill Phillips)、克里斯·斯图尔特 (Chris Stewart)、克莉丝汀·马西卡诺 (Kristin Marsicano) / 王明发 / 人民邮电出版社 / 2017-6 / 129.00元

Big Nerd Ranch 是美国一家专业的移动开发技术培训机构。本书主要以其Android 训练营教学课程为基础,融合了几位作者多年的心得体会,是一本完全面向实战的Android 编程权威指南。全书共36 章,详细介绍了8 个Android 应用的开发过程。通过这些精心设计的应用,读者可掌握很多重要的理论知识和开发技巧,获得宝贵的开发经验。 第3 版较之前版本增加了对数据绑定等新工具的介......一起来看看 《Android编程权威指南(第3版)》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

随机密码生成器
随机密码生成器

多种字符组合密码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具