Function regwexec

Source
pub fn regwexec<'a>(
    compiled_reg: &Regex,
    string: &'a WideStr,
    nmatches: usize,
    flags: RegexecFlags,
) -> Result<RegMatchWideStr<'a>>
Expand description

Performs a regex search on the passed wide string, returning nmatches results.

This is a thin wrapper around Regex::regwexec.

This function should only be used if you need to match wide strings.

§Arguments

§Returns

If no error was found, a Vec of Options will be returned.

If a given match index is empty, The Option will be None. Otherwise, a WideStr will be returned.

§Errors

If an error is encountered during matching, it returns a RegexError.

§Caveats

Unless copied, the match results must live at least as long as string. This is because they are slices into string under the hood, for efficiency.

§Examples

use tre_regex::{RegcompFlags, RegexecFlags, regwcomp, regwexec};
use widestring::widestr;

let regcomp_flags = RegcompFlags::new()
    .add(RegcompFlags::EXTENDED)
    .add(RegcompFlags::ICASE)
    .add(RegcompFlags::UNGREEDY);
let regexec_flags = RegexecFlags::new().add(RegexecFlags::NONE);

let compiled_reg = regwcomp(widestr!("^(hello).*(world)$"), regcomp_flags)?;
let matches = regwexec(
    &compiled_reg,              // Compiled regex
    widestr!("hello world"),    // String to match against
    2,                          // Number of matches
    regexec_flags               // Flags
)?;

for (i, matched) in matches.into_iter().enumerate() {
    match matched {
        Some(substr) => println!("Match {i}: {}", substr.display()),
        None => println!("Match {i}: <None>"),
    }
}