'Find/Replace', 'Filter' and 'Register' now used XRegExp

This commit is contained in:
n1474335 2018-08-23 21:41:57 +01:00
parent 5aa13f2428
commit 1ad079fbd4
3 changed files with 23 additions and 8 deletions

View file

@ -6,6 +6,7 @@
import Operation from "../Operation";
import Utils from "../Utils";
import XRegExp from "xregexp";
/**
* Find / Replace operation
@ -50,6 +51,11 @@ class FindReplace extends Operation {
"name": "Multiline matching",
"type": "boolean",
"value": true
},
{
"name": "Dot matches all",
"type": "boolean",
"value": false
}
];
}
@ -60,16 +66,17 @@ class FindReplace extends Operation {
* @returns {string}
*/
run(input, args) {
const [{option: type}, replace, g, i, m] = args;
const [{option: type}, replace, g, i, m, s] = args;
let find = args[0].string,
modifiers = "";
if (g) modifiers += "g";
if (i) modifiers += "i";
if (m) modifiers += "m";
if (s) modifiers += "s";
if (type === "Regex") {
find = new RegExp(find, modifiers);
find = new XRegExp(find, modifiers);
return input.replace(find, replace);
}
@ -77,7 +84,7 @@ class FindReplace extends Operation {
find = Utils.parseEscapedChars(find);
}
find = new RegExp(Utils.escapeRegex(find), modifiers);
find = new XRegExp(Utils.escapeRegex(find), modifiers);
return input.replace(find, replace);
}