[英]flex (lexical analyzer) regular expressions - Reusing definitions
I have this working definition:我有这个工作定义:
IDENTIFIER [a-zA-Z][a-zA-Z0-9]*
I don't want to keep repeating the [a-zA-Z] and [0-9], so I made two new definitions我不想一直重复[a-zA-Z]和[0-9],所以我做了两个新定义
DIGIT [0-9]
VALID [a-zA-Z]
How can I rewrite the IDENTIFIER rule to use the DIGIT and VALID definitions?如何重写 IDENTIFIER 规则以使用 DIGIT 和 VALID 定义?
I don't know how to do the "second" match, I'm stuck here:我不知道如何进行“第二场”比赛,我被困在这里:
IDENTIFIER {VALID}[{VALID}{DIGIT}]* // This syntax is incorrect
Thanks.谢谢。
Edit: The entire test program that I'm using: http://pastebin.com/f5b64183f .编辑:我正在使用的整个测试程序: http : //pastebin.com/f5b64183f 。
It looks like you actually want:看起来你真的想要:
IDENTIFIER {VALID}({VALID}|{DIGIT})*
[{VALID}{DIGIT}]
resolves to [[A-Za-z][0-9]]
which is not a legal construct. [{VALID}{DIGIT}]
解析为[[A-Za-z][0-9]]
这不是一个合法的结构。
I think this will do it, but I can't test it.我认为这会做到,但我无法测试。 Do you have sample data?
你有样本数据吗?
(?:[a-zA-Z])+(?:[0-9])+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.