Skip to content

Instantly share code, notes, and snippets.

@datfinesoul
Last active March 9, 2021 12:46
Show Gist options
  • Save datfinesoul/1b892e632a27607e335d59d2fa72aabb to your computer and use it in GitHub Desktop.
Save datfinesoul/1b892e632a27607e335d59d2fa72aabb to your computer and use it in GitHub Desktop.
Ability to split regex into multiple lines and add comments in JS
const partition = "aws-cn";
const multilineRegex = (...rest) => new RegExp(rest.map(x => (x instanceof RegExp) ? x.source : x).join(''));
const re = multilineRegex(
/aws:/, // I can COMMENT!!!!
partition,
/:secretsmanager:cn-north-1:111111111111:/
);
console.log({
a: re.test('aws:aws:secretsmanager:cn-north-1:111111111111:'),
b: re.test('aws:aws-cn:secretsmanager:cn-north-1:111111111111:')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment