@@ -427,12 +427,23 @@ impl Regex {
427427 /// Note that using `$2` instead of `$first` or `$1` instead of `$last`
428428 /// would produce the same result. To write a literal `$` use `$$`.
429429 ///
430- /// If `$name` isn't a valid capture group (whether the name doesn't exist
431- /// or isn't a valid index), then it is replaced with the empty string.
430+ /// Sometimes the replacement string requires use of curly braces to
431+ /// delineate a capture group replacement and surrounding literal text.
432+ /// For example, if we wanted to join two words together with an
433+ /// underscore:
432434 ///
433- /// The longest possible name is used. e.g., `$1a` looks up the capture
434- /// group named `1a` and not the capture group at index `1`. To exert more
435- /// precise control over the name, use braces, e.g., `${1}a`.
435+ /// ```rust
436+ /// # extern crate regex; use regex::bytes::Regex;
437+ /// # fn main() {
438+ /// let re = Regex::new(r"(?P<first>\w+)\s+(?P<second>\w+)").unwrap();
439+ /// let result = re.replace(b"deep fried", &b"${first}_$second"[..]);
440+ /// assert_eq!(result, &b"deep_fried"[..]);
441+ /// # }
442+ /// ```
443+ ///
444+ /// Without the curly braces, the capture group name `first_` would be
445+ /// used, and since it doesn't exist, it would be replaced with the empty
446+ /// string.
436447 ///
437448 /// Finally, sometimes you just want to replace a literal string with no
438449 /// regard for capturing group expansion. This can be done by wrapping a
0 commit comments