如何在flex中使用REJECT?
让我们明确一下,我正在谈论词法分析工具。
对于以下输入:
aa bb cc dd
我需要解析器来匹配以下子字符串:
aa bb
bb cc
cc dd
我有这个正则表达式:
[a-zA-Z]+[ ]+[a-zA-Z]+
但这只匹配:
aa bb
<代码>抄送dd
我被告知可以使用 REJECT 命令来获取我需要的输出,但我不知道如何应用它。有人可以帮我吗?
Let's be clear I'm talking about the lexical analysis tool.
For the following input:
aa bb cc dd
I need the parser to match the following sub strings:
aa bb
bb cc
cc dd
I have this regex:
[a-zA-Z]+[ ]+[a-zA-Z]+
But this only matches:
aa bb
cc dd
I've been told the REJECT command can be used to get the output I need but I don't know how to apply it. Could someone give me a hand?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
REJECT 将重新开始扫描,然后您只需“吃掉”已经匹配的第一个字母字符串即可。可能这就是您想要的(10 年前:-):
给定输入字符串:
它将产生:
REJECT will start the scan over, then you just need to "eat" the first alphabetic string that you already matched. Possibly this is what you wanted (10 years ago :-):
Given the input string:
it will produce:
您可以使用正则表达式枚举整个集合中的 n 和 n + 1 对。
查看具有“贪婪”向后(或向前)匹配的分组。
You can use a regex to enumerate n and n + 1 pairs through an entire set.
Look into a grouping with a "greedy" backwards (or forwards) match.
这是 Flex 解决该问题的一种方法:
This is one Flex solution to the problem :