diff --git a/index.js b/index.js index 33be4c2..8b0124a 100644 --- a/index.js +++ b/index.js @@ -102,7 +102,7 @@ function createReplaceFn(replace, isRegEx) { // And string parameters var paramLength = arguments.length - 2; for (var i = 1; i < paramLength; i++) { - newReplace = newReplace.replace('$' + i, arguments[i] || '') + newReplace = newReplace.replace(new RegExp('\\$' + i, 'g'), arguments[i] || '') } return newReplace; }; diff --git a/test/replace.js b/test/replace.js index ef3ab11..b5f4553 100644 --- a/test/replace.js +++ b/test/replace.js @@ -872,12 +872,12 @@ describe('replacestream', function () { }); it('should be able to replace captures using $1 notation', function (done) { - var replace = replaceStream(/(a)(b)/g, 'this is $1 and this is $2'); + var replace = replaceStream(/(a)(b)/g, 'this is $1 and this is $2 and this is again $1'); replace.pipe(concatStream({encoding: 'string'}, function(data) { var expected = [ - 'this is a and this is b', + 'this is a and this is b and this is again a', 'a', - 'this is a and this is b', + 'this is a and this is b and this is again a', 'b' ].join('\n');