Validating strings with any kind of separators falls under a common scheme: "^[p](?:[sep][p])*$". This kind of pattern ensures the separator is not allowed to appear at the start and end of string. REGEX FIDDLE: https://regex101.com/r/CSj2CP/2 FURTHER LINKS: Comma-separated integer numbers in Ruby: https://stackoverflow.com/a/42056966/... Semi-colon separated numbers: https://stackoverflow.com/a/43272505/... Comma-separated numbers with an optional sign in front in HTML pattern attribute: https://stackoverflow.com/a/43097619/... Comma and optional whitespace separated date-like substrings (PCRE): https://stackoverflow.com/a/39992928/... Regex for comma-delimited string with length constraints: https://stackoverflow.com/q/68989289/...