我正在使用的正则表达式是在flex中实现预处理器。 这个预处理器很简单。 它遵守以下规则:
#
符号开头。例如:
#define CONSTANT 100
//...
int x = #CONSTANT;
所以我做的第一件事就是
#define {
//store the identifier following #define in a lookup table
//do the relevant error checking
}
NO_POUND_DEFINE {
//The string should begin with a '#' sign but not with `#define`
//check if the string following '#' is upper case or not
//if in upper case do the lookup otherwise throw an error
}
答案 0 :(得分:2)
var regexp = /^((?!#define).)*$/;
也许你想看看这个:regular-expression-to-match-string-not-containing-a-word
答案 1 :(得分:1)
^#([^d]|d[^e]|de[^f]|def[^i]|defi[^n]|defin[^e]).*
字符串以“#”开头,后跟“d”或后跟“d”,但后面没有“e”等。