【发布时间】:2013-05-28 08:23:51
【问题描述】:
我只需要知道是否可以在正则表达式的定义中包含正则表达式。
这是我想要做的: 我已经为整数、自然数、正整数和负整数定义了正则表达式。现在我想使用这些已经存在的正则表达式来定义分数的正则表达式。
Consider
token_int is the regex for integers
token_natural is the regex for natural numbers
token_neg_int is the regex for negative integers
I would like the fraction regex to be defined as:
token_frac = token_int'/'(token_natural | token_neg_int)
【问题讨论】:
-
如果你的语法变得足够复杂,你应该考虑使用更适合这项工作的分词器/解析器。 PLY 是一个出色的 Python 库,用于定义分词器/解析器。