mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 15:26:16 -04:00
Merge branch 'dev' of https://github.com/n1073645/CyberChef into n1073645-dev
This commit is contained in:
commit
62edd76d7e
2 changed files with 187 additions and 1 deletions
|
@ -32,7 +32,61 @@ class ToCaseInsensitiveRegex extends Operation {
|
|||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
return input.replace(/[a-z]/ig, m => `[${m.toLowerCase()}${m.toUpperCase()}]`);
|
||||
|
||||
/**
|
||||
* Simulates look behind behaviour since javascript doesn't support it.
|
||||
*
|
||||
* @param {string} input
|
||||
* @returns {string}
|
||||
*/
|
||||
function preProcess(input) {
|
||||
let result = "";
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
const temp = input.charAt(i);
|
||||
if (temp.match(/[a-zA-Z]/g) && (input.charAt(i-1) !== "-") && (input.charAt(i+1) !== "-"))
|
||||
result += "[" + temp.toLowerCase() + temp.toUpperCase() + "]";
|
||||
else
|
||||
result += temp;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
try {
|
||||
RegExp(input);
|
||||
} catch (error) {
|
||||
return "Invalid Regular Expression (Please note this version of node does not support look behinds).";
|
||||
}
|
||||
|
||||
// Example: [test] -> [[tT][eE][sS][tT]]
|
||||
return preProcess(input)
|
||||
|
||||
// Example: [A-Z] -> [A-Za-z]
|
||||
.replace(/([A-Z]-[A-Z]|[a-z]-[a-z])/g, m => `${m[0].toUpperCase()}-${m[2].toUpperCase()}${m[0].toLowerCase()}-${m[2].toLowerCase()}`)
|
||||
|
||||
// Example: [H-d] -> [A-DH-dh-z]
|
||||
.replace(/[A-Z]-[a-z]/g, m => `A-${m[2].toUpperCase()}${m}${m[0].toLowerCase()}-z`)
|
||||
|
||||
// Example: [!-D] -> [!-Da-d]
|
||||
.replace(/\\?[ -@]-[A-Z]/g, m => `${m}a-${m[2].toLowerCase()}`)
|
||||
|
||||
// Example: [%-^] -> [%-^a-z]
|
||||
.replace(/\\?[ -@]-\\?[[-`]/g, m => `${m}a-z`)
|
||||
|
||||
// Example: [K-`] -> [K-`k-z]
|
||||
.replace(/[A-Z]-\\?[[-`]/g, m => `${m}${m[0].toLowerCase()}-z`)
|
||||
|
||||
// Example: [[-}] -> [[-}A-Z]
|
||||
.replace(/\\?[[-`]-\\?[{-~]/g, m => `${m}A-Z`)
|
||||
|
||||
// Example: [b-}] -> [b-}B-Z]
|
||||
.replace(/[a-z]-\\?[{-~]/g, m => `${m}${m[0].toUpperCase()}-Z`)
|
||||
|
||||
// Example: [<-j] -> [<-z]
|
||||
.replace(/\\?[ -@]-[a-z]/g, m => `${m[0]}-z`)
|
||||
|
||||
// Example: [^-j] -> [A-J^-j]
|
||||
.replace(/\\?[[-`]-[a-z]/g, m => `A-${m[2].toUpperCase()}${m}`);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue