From 7db0fb303e6c73f475bff12b438a233fb0d1475d Mon Sep 17 00:00:00 2001 From: Nathan Faucett Date: Wed, 22 Apr 2015 17:36:52 -0500 Subject: [PATCH 1/2] replace strings index fix allow replace strings with adjacent text like "$1ies" "$1s" --- src/re.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/re.rs b/src/re.rs index 845f53a010..c4ecd669ba 100644 --- a/src/re.rs +++ b/src/re.rs @@ -780,7 +780,7 @@ impl<'t> Captures<'t> { pub fn expand(&self, text: &str) -> String { // How evil can you get? // FIXME: Don't use regexes for this. It's completely unnecessary. - let re = Regex::new(r"(^|[^$]|\b)\$(\w+)").unwrap(); + let re = Regex::new(r"(^|[^$]|\b)\$(\d+|\w+)").unwrap(); let text = re.replace_all(text, |refs: &Captures| -> String { let pre = refs.at(1).unwrap_or(""); let name = refs.at(2).unwrap_or(""); From 4c423b1b2a2aa4d26758ee534f2f812ce1def889 Mon Sep 17 00:00:00 2001 From: Nathan Faucett Date: Wed, 22 Apr 2015 22:49:34 -0500 Subject: [PATCH 2/2] adjacent index test added test for adjacent index --- regex_macros/tests/tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/regex_macros/tests/tests.rs b/regex_macros/tests/tests.rs index ecd965ff8f..81f3c497c7 100644 --- a/regex_macros/tests/tests.rs +++ b/regex_macros/tests/tests.rs @@ -189,6 +189,8 @@ replace!(rep_all, replace_all, r"\d", "age: 26", "Z", "age: ZZ"); replace!(rep_groups, replace, r"(\S+)\s+(\S+)", "w1 w2", "$2 $1", "w2 w1"); replace!(rep_double_dollar, replace, r"(\S+)\s+(\S+)", "w1 w2", "$2 $$1", "w2 $1"); +replace!(rep_adjacent_index, replace, + r"([^aeiouy])ies$", "skies", "$1y", "sky"); replace!(rep_no_expand, replace, r"(\S+)\s+(\S+)", "w1 w2", NoExpand("$2 $1"), "$2 $1"); replace!(rep_named, replace_all,