107
107
//! let re = Regex::new(r"(\d{4})-(\d{2})-(\d{2})").unwrap();
108
108
//! let text = "2012-03-14, 2013-01-01 and 2014-07-05";
109
109
//! 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]);
113
111
//! }
114
112
//! // Output:
115
113
//! // Month: 03 Day: 14 Year: 2012
225
223
//! # extern crate regex; use regex::Regex;
226
224
//! # fn main() {
227
225
//! 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));
229
228
//! # }
230
229
//! ```
231
230
//!
237
236
//! # extern crate regex; use regex::Regex;
238
237
//! # fn main() {
239
238
//! 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));
241
241
//! # }
242
242
//! ```
243
243
//!
348
348
//! # fn main() {
349
349
//! let re = Regex::new(r"(?i)a+(?-i)b+").unwrap();
350
350
//! let cap = re.captures("AaAaAbbBBBb").unwrap();
351
- //! assert_eq!(cap.at(0), Some( "AaAaAbb") );
351
+ //! assert_eq!(& cap[0], "AaAaAbb");
352
352
//! # }
353
353
//! ```
354
354
//!
363
363
//! # fn main() {
364
364
//! let re = Regex::new(r"(?-u:\b).+(?-u:\b)").unwrap();
365
365
//! let cap = re.captures("$$abc$$").unwrap();
366
- //! assert_eq!(cap.at(0), Some( "abc") );
366
+ //! assert_eq!(& cap[0], "abc");
367
367
//! # }
368
368
//! ```
369
369
//!
@@ -492,7 +492,7 @@ let text = b"foo\x00bar\x00baz\x00";
492
492
// The unwrap is OK here since a match requires the `cstr` capture to match.
493
493
let cstrs: Vec<&[u8]> =
494
494
re.captures_iter(text)
495
- .map(|c| c.name("cstr").unwrap())
495
+ .map(|c| c.name("cstr").unwrap().as_bytes() )
496
496
.collect();
497
497
assert_eq!(vec![&b"foo"[..], &b"bar"[..], &b"baz"[..]], cstrs);
498
498
```
@@ -514,10 +514,11 @@ let caps = re.captures(text).unwrap();
514
514
// Notice that despite the `.*` at the end, it will only match valid UTF-8
515
515
// because Unicode mode was enabled with the `u` flag. Without the `u` flag,
516
516
// 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()));
518
519
519
520
// 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();
521
522
assert_eq!("☃", title);
522
523
```
523
524
0 commit comments