Skip to content

Commit 1e39165

Browse files
committed
capture: Fix docs around non-panicking group queries
Previously in the regex::bytes implementation docs, we missed all of the non-panicking versions that were supposed to be demonstrated. These now show the correct versions. In the str implementation, the indexed capture group examples were correct, but not the named group examples. That's now also fixed.
1 parent 6b342fc commit 1e39165

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/re_bytes.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ impl Regex {
209209
/// let re = Regex::new(r"'([^']+)'\s+\((\d{4})\)").unwrap();
210210
/// let text = b"Not my favorite movie: 'Citizen Kane' (1941).";
211211
/// let caps = re.captures(text).unwrap();
212-
/// assert_eq!(&caps[1], &b"Citizen Kane"[..]);
213-
/// assert_eq!(&caps[2], &b"1941"[..]);
214-
/// assert_eq!(&caps[0], &b"'Citizen Kane' (1941)"[..]);
212+
/// assert_eq!(caps.get(1).unwrap().as_bytes(), &b"Citizen Kane"[..]);
213+
/// assert_eq!(caps.get(2).unwrap().as_bytes(), &b"1941"[..]);
214+
/// assert_eq!(caps.get(0).unwrap().as_bytes(), &b"'Citizen Kane' (1941)"[..]);
215215
/// // You can also access the groups by index using the Index notation.
216216
/// // Note that this will panic on an invalid index.
217217
/// assert_eq!(&caps[1], b"Citizen Kane");
@@ -232,9 +232,9 @@ impl Regex {
232232
/// .unwrap();
233233
/// let text = b"Not my favorite movie: 'Citizen Kane' (1941).";
234234
/// let caps = re.captures(text).unwrap();
235-
/// assert_eq!(&caps["title"], &b"Citizen Kane"[..]);
236-
/// assert_eq!(&caps["year"], &b"1941"[..]);
237-
/// assert_eq!(&caps[0], &b"'Citizen Kane' (1941)"[..]);
235+
/// assert_eq!(caps.name("title").unwrap().as_bytes(), b"Citizen Kane");
236+
/// assert_eq!(caps.name("year").unwrap().as_bytes(), b"1941");
237+
/// assert_eq!(caps.get(0).unwrap().as_bytes(), &b"'Citizen Kane' (1941)"[..]);
238238
/// // You can also access the groups by name using the Index notation.
239239
/// // Note that this will panic on an invalid group name.
240240
/// assert_eq!(&caps["title"], b"Citizen Kane");

src/re_unicode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ impl Regex {
289289
/// .unwrap();
290290
/// let text = "Not my favorite movie: 'Citizen Kane' (1941).";
291291
/// let caps = re.captures(text).unwrap();
292-
/// assert_eq!(&caps["title"], "Citizen Kane");
293-
/// assert_eq!(&caps["year"], "1941");
292+
/// assert_eq!(caps.name("title").unwrap().as_str(), "Citizen Kane");
293+
/// assert_eq!(caps.name("year").unwrap().as_str(), "1941");
294294
/// assert_eq!(caps.get(0).unwrap().as_str(), "'Citizen Kane' (1941)");
295295
/// // You can also access the groups by name using the Index notation.
296296
/// // Note that this will panic on an invalid group name.

0 commit comments

Comments
 (0)