Skip to content

Commit 7311bfc

Browse files
committed
fixup! api: Add as_match method
1 parent 0fc52dc commit 7311bfc

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/regex/bytes.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,16 @@ impl<'h> Captures<'h> {
16681668
/// Return the overall match for the capture.
16691669
///
16701670
/// This returns the match for index `0`. That is it is equivalent to
1671-
/// `get(0).unwrap()`
1671+
/// `m.get(0).unwrap()`
1672+
///
1673+
/// ```
1674+
/// use regex::bytes::Regex;
1675+
///
1676+
/// let re = Regex::new(r"[a-z]+([0-9]+)").unwrap();
1677+
/// let caps = re.captures(b" abc123-def").unwrap();
1678+
///
1679+
/// assert_eq!(caps.as_match().as_bytes(), b"abc123");
1680+
/// ```
16721681
#[inline]
16731682
pub fn as_match(&self) -> Match {
16741683
self.get(0).unwrap()

src/regex/string.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,17 @@ impl<'h> Captures<'h> {
16781678
/// Return the overall match for the capture.
16791679
///
16801680
/// This returns the match for index `0`. That is it is equivalent to
1681-
/// `get(0).unwrap()`
1681+
/// `m.get(0).unwrap()`
1682+
///
1683+
/// ```
1684+
/// use regex::Regex;
1685+
///
1686+
/// let re = Regex::new(r"[a-z]+([0-9]+)").unwrap();
1687+
/// let caps = re.captures(" abc123-def").unwrap();
1688+
///
1689+
/// assert_eq!(caps.as_match().as_str(), "abc123");
1690+
///
1691+
/// ```
16821692
#[inline]
16831693
pub fn as_match(&self) -> Match {
16841694
self.get(0).unwrap()

0 commit comments

Comments
 (0)