Detect regex in metric queries.

This commit is contained in:
Alexander Zobnin
2016-01-17 14:11:11 +03:00
parent 7a73449828
commit 0bbfa3910a
3 changed files with 61 additions and 15 deletions

View File

@@ -28,5 +28,20 @@ function (angular, _) {
}
return name;
};
// Pattern for testing regex
var regexPattern = /^\/(.*)\/([gmi]*)$/m;
this.isRegex = function (str) {
return regexPattern.test(str);
};
this.buildRegex = function (str) {
var matches = str.match(regexPattern);
var pattern = matches[1];
var flags = matches[2] !== "" ? matches[2] : undefined;
return new RegExp(pattern, flags);
};
});
});