I've been reading through the documentation for nom
6.2.1 and I'm trying to construct a parser which will match any number of characters (including zero) followed by the word foobar: /.*foobar/
.
nom::bytes::complete::take_until("foobar")
almost does what I want, but it will not consume foobar
itself, so I'd have to instead do:
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)
}
I tend to think in terms of the traditional regular expression syntax and then have to map that to the available constructs that nom
provides. I'm getting better at noticing scenarios where the nom
constructs fit better, but is there a regex-to-nom cheatsheet?