Skip to content

Commit

Permalink
Merge pull request #80 from nathanfaucett/patch-1
Browse files Browse the repository at this point in the history
replace strings index fix
  • Loading branch information
BurntSushi committed Apr 23, 2015
2 parents 93f3798 + 4c423b1 commit 45b6739
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions regex_macros/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/re.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand Down

0 comments on commit 45b6739

Please sign in to comment.