-
Notifications
You must be signed in to change notification settings - Fork 494
Closed
Description
The regular express ((IMG|CAM|MG|MB2)_|(DSCN|CIMG))(?P<n>[0-9]+)$ is a match on the text "CIMG2341" but expected result of regex.replace("CIMG2341", "$n") returns "2341" is not found, instead "CIMG2341" is returned. The correct behavior is observer when the original regex is replaced with ((MG|MB2)_|(DSCN|CIMG))(?P<n>[0-9]+)$.
extern crate regex;
use regex::{Regex};
fn main() {
let text = "CIMG2341";
let regex = Regex::new(
"((IMG|CAM|MG|MB2)_|(DSCN|CIMG))(?P<n>[0-9]+)$").unwrap();
assert!(regex.is_match(text)); // This works (no panic)
let renamed = regex.replace(text, "$n");
assert_eq!(renamed, "2341"); // This panics
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels