File tree Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 1
- 1.11.4 (TBD)
1
+ 1.12.0 (TBD)
2
2
============
3
3
TODO
4
4
5
+ Improvements:
6
+
7
+ * [ FEATURE #1146 ] ( https://github.com/rust-lang/regex/issues/1146 ) :
8
+ Add ` Capture::get_match ` for returning the overall match without ` unwrap() ` .
9
+
5
10
Bug fixes:
6
11
7
12
* [ BUG #1116 ] ( https://github.com/rust-lang/regex/issues/1116 ) :
Original file line number Diff line number Diff line change @@ -1665,6 +1665,26 @@ impl<'h> Captures<'h> {
1665
1665
. map ( |sp| Match :: new ( self . haystack , sp. start , sp. end ) )
1666
1666
}
1667
1667
1668
+ /// Return the overall match for the capture.
1669
+ ///
1670
+ /// This returns the match for index `0`. That is it is equivalent to
1671
+ /// `m.get(0).unwrap()`
1672
+ ///
1673
+ /// # Example
1674
+ ///
1675
+ /// ```
1676
+ /// use regex::bytes::Regex;
1677
+ ///
1678
+ /// let re = Regex::new(r"[a-z]+([0-9]+)").unwrap();
1679
+ /// let caps = re.captures(b" abc123-def").unwrap();
1680
+ ///
1681
+ /// assert_eq!(caps.get_match().as_bytes(), b"abc123");
1682
+ /// ```
1683
+ #[ inline]
1684
+ pub fn get_match ( & self ) -> Match {
1685
+ self . get ( 0 ) . unwrap ( )
1686
+ }
1687
+
1668
1688
/// Returns the `Match` associated with the capture group named `name`. If
1669
1689
/// `name` isn't a valid capture group or it refers to a group that didn't
1670
1690
/// match, then `None` is returned.
Original file line number Diff line number Diff line change @@ -1675,6 +1675,27 @@ impl<'h> Captures<'h> {
1675
1675
. map ( |sp| Match :: new ( self . haystack , sp. start , sp. end ) )
1676
1676
}
1677
1677
1678
+ /// Return the overall match for the capture.
1679
+ ///
1680
+ /// This returns the match for index `0`. That is it is equivalent to
1681
+ /// `m.get(0).unwrap()`
1682
+ ///
1683
+ /// # Example
1684
+ ///
1685
+ /// ```
1686
+ /// use regex::Regex;
1687
+ ///
1688
+ /// let re = Regex::new(r"[a-z]+([0-9]+)").unwrap();
1689
+ /// let caps = re.captures(" abc123-def").unwrap();
1690
+ ///
1691
+ /// assert_eq!(caps.get_match().as_str(), "abc123");
1692
+ ///
1693
+ /// ```
1694
+ #[ inline]
1695
+ pub fn get_match ( & self ) -> Match {
1696
+ self . get ( 0 ) . unwrap ( )
1697
+ }
1698
+
1678
1699
/// Returns the `Match` associated with the capture group named `name`. If
1679
1700
/// `name` isn't a valid capture group or it refers to a group that didn't
1680
1701
/// match, then `None` is returned.
You can’t perform that action at this time.
0 commit comments