简体   繁体   中英

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 + ')'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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