diff --git a/src/core/operations/Filter.mjs b/src/core/operations/Filter.mjs index aaf53f0f..64a97279 100644 --- a/src/core/operations/Filter.mjs +++ b/src/core/operations/Filter.mjs @@ -8,6 +8,7 @@ import Operation from "../Operation"; import Utils from "../Utils"; import {INPUT_DELIM_OPTIONS} from "../lib/Delim"; import OperationError from "../errors/OperationError"; +import XRegExp from "xregexp"; /** * Filter operation @@ -21,7 +22,7 @@ class Filter extends Operation { super(); this.name = "Filter"; - this.module = "Default"; + this.module = "Regex"; this.description = "Splits up the input using the specified delimiter and then filters each branch based on a regular expression."; this.inputType = "string"; this.outputType = "string"; @@ -55,7 +56,7 @@ class Filter extends Operation { let regex; try { - regex = new RegExp(args[1]); + regex = new XRegExp(args[1]); } catch (err) { throw new OperationError(`Invalid regex. Details: ${err.message}`); } diff --git a/src/core/operations/FindReplace.mjs b/src/core/operations/FindReplace.mjs index 62faf2cb..af75fcb0 100644 --- a/src/core/operations/FindReplace.mjs +++ b/src/core/operations/FindReplace.mjs @@ -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); } diff --git a/src/core/operations/Register.mjs b/src/core/operations/Register.mjs index 29e1cd50..3b0d7479 100644 --- a/src/core/operations/Register.mjs +++ b/src/core/operations/Register.mjs @@ -6,6 +6,7 @@ import Operation from "../Operation"; import Dish from "../Dish"; +import XRegExp from "xregexp"; /** * Register operation @@ -20,7 +21,7 @@ class Register extends Operation { this.name = "Register"; this.flowControl = true; - this.module = "Default"; + this.module = "Regex"; this.description = "Extract data from the input and store it in registers which can then be passed into subsequent operations as arguments. Regular expression capture groups are used to select the data to extract.

To use registers in arguments, refer to them using the notation $Rn where n is the register number, starting at 0.

For example:
Input: Test
Extractor: (.*)
Argument: $R0 becomes Test

Registers can be escaped in arguments using a backslash. e.g. \\$R0 would become $R0 rather than Test."; this.infoURL = "https://wikipedia.org/wiki/Regular_expression#Syntax"; this.inputType = "string"; @@ -40,6 +41,11 @@ class Register extends Operation { "name": "Multiline matching", "type": "boolean", "value": false + }, + { + "name": "Dot matches all", + "type": "boolean", + "value": false } ]; } @@ -53,13 +59,14 @@ class Register extends Operation { */ async run(state) { const ings = state.opList[state.progress].ingValues; - const [extractorStr, i, m] = ings; + const [extractorStr, i, m, s] = ings; let modifiers = ""; if (i) modifiers += "i"; if (m) modifiers += "m"; + if (s) modifiers += "s"; - const extractor = new RegExp(extractorStr, modifiers), + const extractor = new XRegExp(extractorStr, modifiers), input = await state.dish.get(Dish.STRING), registers = input.match(extractor);