mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
16 lines
382 B
TypeScript
16 lines
382 B
TypeScript
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]);
|
|
};
|