简体   繁体   English

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

[英]Regular expression in a regular expression?

I just needed to know if its possible to have a regular expression inside the definition of a regular expression. 我只需要知道是否有可能在正则表达式的定义内包含一个正则表达式。

Here is what I am trying to do: I have defined regular expressions for Integers, Natural numbers, Positive Integers and Negative integers. 这是我要尝试做的事情:我已经为整数,自然数,正整数和负整数定义了正则表达式。 Now I would like to use these already existing regular expressions to define the regular expression for fraction. 现在,我想使用这些已经存在的正则表达式来定义分数的正则表达式。

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)

If I correctly understand you then yes. 如果我对您的理解正确,那么可以。 But in the following manner (since regular expressions are strings): 但是以以下方式(由于正则表达式是字符串):

token_frac = token_int + '/(' + token_natural + '|' + token_neg_int + ')'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM