Last active
April 10, 2024 21:39
-
-
Save albannurkollari/7e045eafdc29f7fdb3da243dbffc55c1 to your computer and use it in GitHub Desktop.
Regex with ocurrence pattern helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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