diff --git a/public/app/features/templating/templateSrv.js b/public/app/features/templating/templateSrv.js index 7e96af22e2a..e2e628c1cd5 100644 --- a/public/app/features/templating/templateSrv.js +++ b/public/app/features/templating/templateSrv.js @@ -97,8 +97,11 @@ function (angular, _) { if (!str) { return false; } - var match = this._regex.exec(str); - return match && (match[1] === variableName || match[2] === variableName); + + variableName = regexEscape(variableName); + var findVarRegex = new RegExp('\\$(' + variableName + ')[\\W|$]|\\[\\[(' + variableName + ')\\]\\]', 'g'); + var match = findVarRegex.exec(str); + return match !== null; }; this.highlightVariablesAsHtml = function(str) { diff --git a/public/test/specs/templateSrv-specs.js b/public/test/specs/templateSrv-specs.js index fd7247cbd81..c1f0e25ff9e 100644 --- a/public/test/specs/templateSrv-specs.js +++ b/public/test/specs/templateSrv-specs.js @@ -200,6 +200,11 @@ define([ expect(contains).to.be(true); }); + it('should find it when part of segment', function() { + var contains = _templateSrv.containsVariable('metrics.$env.$group-*', 'group'); + expect(contains).to.be(true); + }); + }); describe('updateTemplateData with simple value', function() {