diff --git a/public/app/features/templating/templateSrv.js b/public/app/features/templating/templateSrv.js index 2e5f945c96a..b8d6cbaee2d 100644 --- a/public/app/features/templating/templateSrv.js +++ b/public/app/features/templating/templateSrv.js @@ -103,7 +103,7 @@ function (angular, _) { } variableName = regexEscape(variableName); - var findVarRegex = new RegExp('\\$(' + variableName + ')[\\W|$]|\\[\\[(' + variableName + ')\\]\\]', 'g'); + var findVarRegex = new RegExp('\\$(' + variableName + ')(?:\\W|$)|\\[\\[(' + variableName + ')\\]\\]', 'g'); var match = findVarRegex.exec(str); return match !== null; }; diff --git a/public/test/specs/templateSrv-specs.js b/public/test/specs/templateSrv-specs.js index c5f33d4f72f..a592cc7a152 100644 --- a/public/test/specs/templateSrv-specs.js +++ b/public/test/specs/templateSrv-specs.js @@ -205,6 +205,10 @@ define([ expect(contains).to.be(true); }); + it('should find it its the only thing', function() { + var contains = _templateSrv.containsVariable('$env', 'env'); + expect(contains).to.be(true); + }); }); describe('updateTemplateData with simple value', function() {