Index: lib/common.js |
=================================================================== |
--- a/lib/common.js |
+++ b/lib/common.js |
@@ -27,42 +27,53 @@ |
return text.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); |
} |
exports.textToRegExp = textToRegExp; |
/** |
* Converts filter text into regular expression string |
* @param {string} text as in Filter() |
+ * @param {boolean} [captureAll=false] whether to enable the capturing of |
+ * leading and trailing wildcards in the filter text; by default, leading and |
+ * trailing wildcards are stripped out |
* @return {string} regular expression representation of filter text |
*/ |
-function filterToRegExp(text) |
+function filterToRegExp(text, captureAll = false) |
{ |
+ // remove multiple wildcards |
+ text = text.replace(/\*+/g, "*"); |
+ |
+ if (!captureAll) |
+ { |
+ // remove leading wildcard |
+ if (text[0] == "*") |
+ text = text.substring(1); |
+ |
+ // remove trailing wildcard |
+ if (text[text.length - 1] == "*") |
+ text = text.substring(0, text.length - 1); |
+ } |
+ |
return text |
- // remove multiple wildcards |
- .replace(/\*+/g, "*") |
// remove anchors following separator placeholder |
.replace(/\^\|$/, "^") |
// escape special symbols |
.replace(/\W/g, "\\$&") |
// replace wildcards by .* |
.replace(/\\\*/g, ".*") |
// process separator placeholders (all ANSI characters but alphanumeric |
// characters and _%.-) |
.replace(/\\\^/g, "(?:[\\x00-\\x24\\x26-\\x2C\\x2F\\x3A-\\x40\\x5B-\\x5E\\x60\\x7B-\\x7F]|$)") |
// process extended anchor at expression start |
.replace(/^\\\|\\\|/, "^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?") |
// process anchor at expression start |
.replace(/^\\\|/, "^") |
// process anchor at expression end |
- .replace(/\\\|$/, "$") |
- // remove leading wildcards |
- .replace(/^(\.\*)/, "") |
- // remove trailing wildcards |
- .replace(/(\.\*)$/, ""); |
+ .replace(/\\\|$/, "$"); |
} |
exports.filterToRegExp = filterToRegExp; |
function splitSelector(selector) |
{ |
if (!selector.includes(",")) |
return [selector]; |