Test, validate and match regular expressions
Matches an optional comma at the very beginning of a string (^,?) or an optional comma at the very end (,?$). With the global flag and empty-string replacement, it strips leading and trailing commas, ideal for cleaning up delimited lists such as ',a,b,c,' to 'a,b,c'. Commonly used to sanitize CSV-like strings or dynamically built comma-separated values.