Closed as not planned
Description
What version of regex are you using?
1.8.4
Describe the bug at a high level.
The documentation declares:
Capture group names must be any sequence of alpha-numeric Unicode codepoints, in addition to ., _, [ and ]. Names must start with either an _ or an alphabetic codepoint. Alphabetic codepoints correspond to the Alphabetic Unicode property, while numeric codepoints correspond to the union of the Decimal_Number, Letter_Number and Other_Number general categories.
so i consider the expan expression $1_cpu
will refer to the capture group index 1. Actually, expand treats it as named capture group 1_cpu
, which lead to empty result. This behavior is incorrect, because capture group name cannot start with digit.
What are the steps to reproduce the behavior?
What is the actual behavior?
use regex::Regex;
fn main() {
let s = "cpu_user";
let rx = Regex::new("cpu_(.*)").unwrap();
let caps = rx.captures(s).unwrap();
let mut x = String::new();
caps.expand("$1_cpu", &mut x);
println!("result = {:?}", x);
}
Returns output:
result = ""
What is the expected behavior?
Expected output:
result = "user_cpu"
Other notes
Expanding of ${1}_cpu
works as expected. The expression cpu_$1
is already expanded properly.