mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 15:26:16 -04:00
'Find/Replace', 'Filter' and 'Register' now used XRegExp
This commit is contained in:
parent
5aa13f2428
commit
1ad079fbd4
3 changed files with 23 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue