Regex in Rust
Get to know regular expression in Rust.
First import crate “Regex” to “Cargo.toml” file.
regex = "1.4.2"
Run some test
use regex::Regex;
let re = Regex::new(r"first: \d+").unwrap();
assert_eq!(re.replace(", offset: 0, first: 20, filter: $filter","first: 1"),", offset: 0, first: 1, filter: $filter");
Here we find the string that match pattern r”first: \d+” . And will try to replace the match text with other value. In this case it is “first: 1”.
Hope it helps.
~~ PEACE ~~