Skip to content

Instantly share code, notes, and snippets.

@albannurkollari
Last active April 10, 2024 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albannurkollari/7e045eafdc29f7fdb3da243dbffc55c1 to your computer and use it in GitHub Desktop.
Save albannurkollari/7e045eafdc29f7fdb3da243dbffc55c1 to your computer and use it in GitHub Desktop.
Regex with ocurrence pattern helper
export const regexWithOccurrencePattern = (regex: RegExp | string) => {
const source = regex instanceof RegExp ? regex.source : regex;
return new RegExp(`^${source}((,${source})+)?$`);
};
export const KEY_VALUE_PAIRS_REGEX = regexWithOccurrencePattern(/\w+=\w+/);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment