Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Match A String Until A Case Insensitive Tag With nom In Rust

See the second one if you want to keep the text

rust
//! ```cargo
//! [dependencies]
//! nom = "7.1.3"
//! ```

use nom::IResult;
use nom::multi::many_till;
use nom::character::complete::anychar;
use nom::bytes::complete::tag_no_case;

fn main() {
    let source = "the quick brown fox";
    let result = parse(source).unwrap().1;
    println!("{:?}", result);
}

fn parse(source: &str) -> IResult<&str, String> {
    let (source, result) = many_till(anychar, tag_no_case(" brown"))(source)?;
    let result: String = result.0.iter().collect();
    Ok((
        source,
        result
    ))
}
results start
rust
//! ```cargo
//! [dependencies]
//! nom = "7.1.3"
//! ```

use nom::IResult;
use nom::multi::many_till;
use nom::character::complete::anychar;
// use nom::bytes::complete::tag_no_case;
// use nom::sequence::pair;
// use nom::bytes::complete::take_until;
use nom::bytes::complete::tag;
use nom::combinator::peek;

fn main() {
    let source = "the quick brown fox";
    let result = parse(source);
    dbg!(result.unwrap());
}

fn parse(source: &str) -> IResult<&str, String> {
    let (source, result) = many_till(anychar, peek(tag(" brown")))(source)?;
    let result: String = result.0.iter().collect();
    Ok((
        source,
        result
    ))
}
results start