1
0
Fork 0
forked from svrjs/svrjs
This repository has been archived on 2024-11-10. You can view files and clone it, but cannot push or open issues or pull requests.
svrjs/src/utils/createRegex.js

14 lines
469 B
JavaScript
Raw Normal View History

2024-08-24 08:02:11 +02:00
const os = require("os");
function createRegex(regex, isPath) {
2024-08-24 08:07:31 +02:00
const regexStrMatch = regex.match(/^\/((?:\\.|[^\/\\])*)\/([a-zA-Z0-9]*)$/);
if (!regexStrMatch) throw new Error("Invalid regular expression: " + regex);
const searchString = regexStrMatch[1];
let modifiers = regexStrMatch[2];
if (isPath && !modifiers.match(/i/i) && os.platform() == "win32")
modifiers += "i";
return new RegExp(searchString, modifiers);
}
2024-08-24 08:02:11 +02:00
2024-08-24 08:07:31 +02:00
module.exports = createRegex;