所有以“#”开头的文本的正则表达式但不是#define

发布于 2024-12-04 01:59:57 字数 685 浏览 5 评论 0原文

我使用的正则表达式用于在 Flex 中实现预处理器。 这个预处理器有点简单。 它遵循以下规则:

  1. 预处理器指令以 #define 开头,后跟大写字母的标识符;
  2. 预处理器标识符的用例以 # 符号开头。

例如:

#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
                }

the regex i am using is for an implementation of preprocessor, in flex.
This preprocessor is kindof simple.
It obeys following rules:

  1. the preprocessor directive starts with #define followed by identifier in capital letters
  2. the use-case of preprocessor identifier begins with a # sign.

for example:

#define CONSTANT 100
//...
int x = #CONSTANT;

so first thing i did was

#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
                }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三生一梦 2024-12-11 01:59:58

^#([^d]|d[^e]|de[^f]|def[^i]|defi[^n]|defin[^e]).* 字符串开始带有“#”后不跟“d”或后跟“d”但后不跟“e”等。

^#([^d]|d[^e]|de[^f]|def[^i]|defi[^n]|defin[^e]).* The string starts with a '#' not followed by a 'd' or followed by a 'd' but not followed by an 'e' etc.

固执像三岁 2024-12-11 01:59:57
var regexp = /^((?!#define).)*$/;

也许您想看看这个: regular-expression-匹配不包含单词的字符串

var regexp = /^((?!#define).)*$/;

Maybe you want to take a look at this: regular-expression-to-match-string-not-containing-a-word

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文