正则表达式中超过100个捕获组 [英] more than 100 capturing groups in a regex

查看:163
本文介绍了正则表达式中超过100个捕获组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


Python正则表达式不得超过100个捕获

组。负责此的源代码如下:

#XXX:< fl>摆脱这个限制!

如果p.pattern.groups> 100:

引发AssertionError(

抱歉,但此版本仅支持100个命名组



我已经等了很长时间才让Python摆脱这个

的限制。

我可以用更快的速度制作我的程序如果Python没有它就容易入侵。


我的问题是:有没有人知道问题是否会在
$中修复b $ b未来几个月左右?或者有没有办法绕过它?

J?rg Schuster

Hello,

Python regular expressions must not have more than 100 capturing
groups. The source code responsible for this reads as follows:
# XXX: <fl> get rid of this limitation!
if p.pattern.groups > 100:
raise AssertionError(
"sorry, but this version only supports 100 named groups"
)

I have been waiting a long time now for Python to get rid of this
limitation.
I could make a program of mine a lot faster with an easy hack if Python
did not have it.

My question is: Does anyone know if the problem is going to be fixed in
the next few months or so? Or is there a way to circumvent it?
J?rg Schuster

推荐答案

Joerg>或者有没有办法绕过[捕获群体限制]?


当然,向SourceForge提交补丁以取消限制。


我即使我从

更高级别的表示中生成正则表达式,也永远不会创建需要

捕获100个组的正则表达式。我怀疑很少有人会达到这个限制。

也许解释是什么促使你想要抓住那么多团体。

其他人可能会建议替代品。请记住:


有些人在面对问题时会想我知道,我会使用

正则表达式。现在他们有两个问题。 --Jamie Zawinski


Skip
Joerg> Or is there a way to circumvent [capturing groups limitation]?

Sure, submit a patch to SourceForge that removes the restriction.

I''ve never come anywhere close to creating regular expressions that need to
capture 100 groups even though I generate regular expressions from a
higher-level representation. I suspect few will have hit that limit.
Perhaps explain what motivates you to want to capture that many groups.
Other people may be able to suggest alternatives. And remember:

Some people, when confronted with a problem, think "I know, I''ll use
regular expressions." Now they have two problems. --Jamie Zawinski

Skip


>有些人在遇到问题时会想到我知道,
> Some people, when confronted with a problem, think "I know,
我会使用正则表达式。现在他们有两个问题。
--Jamie Zawinski
I''ll use regular expressions." Now they have two problems.
--Jamie Zawinski




感谢引用。


如果我的目标曾经重新设计我的程序,我不会问关于正则表达式的问题

。我没有时间重新设计我的

计划。并且知道我的情况会更好,如果我过去用其他代码编写过
对我没有帮助。


我只是想使用超过100个捕获组。如果有人告诉我

,Python不太可能摆脱上述限制,

我将使用pcre在C ++中重新编写部分程序。但是我希望

能够在Python中完成所有工作。这就是我问的原因。

J?rg



Thanks for the citation.

If my goal had been to redesign my program, I would not ask questions
about regular expressions. I do not have the time to redesign my
program. And knowing that my situation would be better, if I had
written other code in the past, does not help me at all.

I just want to use more than 100 capturing groups. If someone told me
that it is very unlikely for Python to get rid of the said limitation,
I would recode part of my program in C++ using pcre. But I would prefer
to be able to do everything in Python. That is why I asked.

J?rg


Joerg Schuster写道:
Joerg Schuster wrote:
我只想使用超过100个捕获组。如果有人告诉我,Python不太可能摆脱上述限制,我将使用pcre在C ++中重新编写部分程序。
I just want to use more than 100 capturing groups. If someone told me
that it is very unlikely for Python to get rid of the said limitation,
I would recode part of my program in C++ using pcre.



Python不太可能摆脱上述限制。


-Peter



It is very unlikely for Python to get rid of the said limitation.

-Peter


这篇关于正则表达式中超过100个捕获组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆