// Extract all of the strings without the NUL terminator from each match. // The unwrap is OK here since a match requires the `cstr` capture to match. letcstrs:Vec<&[u8]>= re.captures_iter(hay) .map(|c|c.name("cstr").unwrap().as_bytes()) .collect(); assert_eq!(cstrs,vec![&b"foo"[..],&b"qu\xFFux"[..],&b"baz"[..]]); ```
// Notice that despite the `.*` at the end, it will only match valid UTF-8 // because Unicode mode was enabled with the `u` flag. Without the `u` flag, // the `.*` would match the rest of the bytes regardless of whether they were // valid UTF-8. let(_,[title])=re.captures(hay).unwrap().extract(); assert_eq!(title,b"\xE2\x98\x83"); // We can UTF-8 decode the title now. And the unwrap here // is correct because the existence of a match guarantees // that `title` is valid UTF-8. lettitle=std::str::from_utf8(title).unwrap(); assert_eq!(title,"☃"); ```
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.