正则表达式可以导出RPN(逆波兰表示法)或后缀表示法吗
我想知道是否可以定义一个正则表达式来检查给定的输入是否与 RPN 表达式匹配,即给定的输入是否有效?
不幸的是,我对正则表达式不是很熟悉,所以我想知道是否可以定义一个正则表达式来验证后缀的输入。
非常感谢 塔兹
I was wondering if I can define a Regular Expression to check whether a given input matches the RPN expression , i.e. whether the given input is valuid or not?
I am not very familiar with Regex unfortunately, so I was wondering if it is possible to define a regular expression to validate the input for postfix.
Many thanks
Taz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正式来说,不; RPN 需要上下文无关语法,而正则表达式无法表达该语法。但是,可以使用“正则表达式”包或库来实现此目的,因为它们可以包含正则表达式正式定义之外的功能。
Formally, no; RPN would require a context-free grammar, which regular expressions cannot express. However, it might be possible to do so with a "regular expression" package or library, since they can contain features that are outside of the formal definition of regular expressions.