pub fn regcomp_bytes(reg: &[u8], flags: RegcompFlags) -> Result<Regex>
Expand description
Compiles a regex that is in the form of bytes.
This is a thin wrapper around Regex::new_bytes
.
§Arguments
reg
: regular expression to compile, as a string.flags
:RegcompFlags
to pass to the function.
§Returns
An opaque Regex
object will be returned.
§Errors
Will return a RegexError
upon failure.
§Examples
use tre_regex::{RegcompFlags, RegexecFlags, regcomp_bytes, regexec_bytes};
let regcomp_flags = RegcompFlags::new().add(RegcompFlags::EXTENDED);
let regexec_flags = RegexecFlags::new().add(RegexecFlags::NONE);
let compiled_reg = regcomp_bytes(b"[[:digit:]]*", regcomp_flags)?;
let matches = regexec_bytes(&compiled_reg, b"01234567890", 1, regexec_flags)?;
for (i, matched) in matches.into_iter().enumerate() {
match matched {
Some(substr) => println!("Match {i}: '{}'",
std::str::from_utf8(substr.as_ref()).unwrap()
),
None => println!("Match {i}: <None>"),
}
}