1
我只需要知道它是否可能在正則表達式的定義內部具有正則表達式。正則表達式中的正則表達式?
這是我想要做的: 我已經定義了整數,自然數,正整數和負整數的正則表達式。現在我想使用這些已經存在的正則表達式來定義分數的正則表達式。
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庫。 – Patashu