Python 正则表达式中的正则表达式?

Python 正则表达式中的正则表达式?,python,regex,Python,Regex,我只是想知道在正则表达式的定义中是否可能有一个正则表达式 以下是我试图做的: 我定义了整数、自然数、正整数和负整数的正则表达式。现在我想使用这些已经存在的正则表达式来定义分数的正则表达式 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 t

我只是想知道在正则表达式的定义中是否可能有一个正则表达式

以下是我试图做的: 我定义了整数、自然数、正整数和负整数的正则表达式。现在我想使用这些已经存在的正则表达式来定义分数的正则表达式

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库。
token_frac = token_int + '/(' + token_natural + '|' + token_neg_int + ')'