107107//! let re = Regex::new(r"(\d{4})-(\d{2})-(\d{2})").unwrap();
108108//! let text = "2012-03-14, 2013-01-01 and 2014-07-05";
109109//! for cap in re.captures_iter(text) {
110- //! println!("Month: {} Day: {} Year: {}",
111- //! cap.at(2).unwrap_or(""), cap.at(3).unwrap_or(""),
112- //! cap.at(1).unwrap_or(""));
110+ //! println!("Month: {} Day: {} Year: {}", &cap[2], &cap[3], &cap[1]);
113111//! }
114112//! // Output:
115113//! // Month: 03 Day: 14 Year: 2012
225223//! # extern crate regex; use regex::Regex;
226224//! # fn main() {
227225//! let re = Regex::new(r"(?i)Δ+").unwrap();
228- //! assert_eq!(re.find("ΔδΔ"), Some((0, 6)));
226+ //! let mat = re.find("ΔδΔ").unwrap();
227+ //! assert_eq!((mat.start(), mat.end()), (0, 6));
229228//! # }
230229//! ```
231230//!
237236//! # extern crate regex; use regex::Regex;
238237//! # fn main() {
239238//! let re = Regex::new(r"[\pN\p{Greek}\p{Cherokee}]+").unwrap();
240- //! assert_eq!(re.find("abcΔᎠβⅠᏴγδⅡxyz"), Some((3, 23)));
239+ //! let mat = re.find("abcΔᎠβⅠᏴγδⅡxyz").unwrap();
240+ //! assert_eq!((mat.start(), mat.end()), (3, 23));
241241//! # }
242242//! ```
243243//!
348348//! # fn main() {
349349//! let re = Regex::new(r"(?i)a+(?-i)b+").unwrap();
350350//! let cap = re.captures("AaAaAbbBBBb").unwrap();
351- //! assert_eq!(cap.at(0), Some( "AaAaAbb") );
351+ //! assert_eq!(& cap[0], "AaAaAbb");
352352//! # }
353353//! ```
354354//!
363363//! # fn main() {
364364//! let re = Regex::new(r"(?-u:\b).+(?-u:\b)").unwrap();
365365//! let cap = re.captures("$$abc$$").unwrap();
366- //! assert_eq!(cap.at(0), Some( "abc") );
366+ //! assert_eq!(& cap[0], "abc");
367367//! # }
368368//! ```
369369//!
@@ -462,7 +462,7 @@ pub use re_builder::unicode::*;
462462pub use re_set:: unicode:: * ;
463463pub use re_trait:: { Locations , SubCapturesPosIter } ;
464464pub use re_unicode:: {
465- Regex , Captures , SubCapturesIter , SubCapturesNamedIter ,
465+ Regex , Match , Captures , SubCapturesIter , SubCapturesNamedIter ,
466466 CaptureNamesIter , CapturesIter , FindIter ,
467467 Replacer , NoExpand , SplitsIter , SplitsNIter ,
468468 quote,
@@ -492,7 +492,7 @@ let text = b"foo\x00bar\x00baz\x00";
492492// The unwrap is OK here since a match requires the `cstr` capture to match.
493493let cstrs: Vec<&[u8]> =
494494 re.captures_iter(text)
495- .map(|c| c.name("cstr").unwrap())
495+ .map(|c| c.name("cstr").unwrap().as_bytes() )
496496 .collect();
497497assert_eq!(vec![&b"foo"[..], &b"bar"[..], &b"baz"[..]], cstrs);
498498```
@@ -514,10 +514,11 @@ let caps = re.captures(text).unwrap();
514514// Notice that despite the `.*` at the end, it will only match valid UTF-8
515515// because Unicode mode was enabled with the `u` flag. Without the `u` flag,
516516// the `.*` would match the rest of the bytes.
517- assert_eq!((7, 10), caps.pos(1).unwrap());
517+ let mat = caps.get(1).unwrap();
518+ assert_eq!((7, 10), (mat.start(), mat.end()));
518519
519520// If there was a match, Unicode mode guarantees that `title` is valid UTF-8.
520- let title = str::from_utf8(caps.at(1).unwrap() ).unwrap();
521+ let title = str::from_utf8(& caps[1] ).unwrap();
521522assert_eq!("☃", title);
522523```
523524
0 commit comments