微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

模式 /.*foobar/ 的等效 `nom` 解析器/组合器是什么

如何解决模式 /.*foobar/ 的等效 `nom` 解析器/组合器是什么

我已经阅读了 nom 6.2.1 的 the documentation,我正在尝试构建一个解析器,该解析器将匹配任意数量的字符(包括零)后跟单词 foobar:{ {1}}。

/.*foobar/ 几乎可以做我想做的事,但它不会消耗 nom::bytes::complete::take_until("foobar") 本身,所以我不得不这样做:

foobar

我倾向于考虑传统的正则表达式语法,然后必须将其映射到 use nom::bytes::complete::{tag,take_until}; use nom::combinator::value; use nom::sequence::tuple; use nom::IResult; // This method does what I want,but is verbose because foobar is repeated fn arbitrary_and_then_foobar(s: &str) -> IResult<&str,()> { value((),tuple((take_until("foobar"),tag("foobar"))))(s) } 提供的可用结构。我越来越善于注意到 nom 构造更适合的场景,但是否有正则表达式到nom 备忘单?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。