dockerfile/examples/omnivore/api/liqe/src/parseRegex.ts

17 lines
382 B
TypeScript
Raw Normal View History

2024-03-15 14:52:38 +08:00
const RegExpRule = /(\/?)(.+)\1([a-z]*)/;
const FlagRule = /^(?!.*?(.).*?\1)[AJUXgimsux]+$/;
export const parseRegex = (subject: string): RegExp => {
const match = RegExpRule.exec(subject);
if (!match) {
throw new Error('Invalid RegExp.');
}
if (match[3] && !FlagRule.test(match[3])) {
return new RegExp(subject);
}
return new RegExp(match[2], match[3]);
};