Your regex doesn’t work because first, you’ve put the regex into quotes, so you’re checking if your string contains this substring: '/^[\s,]$/g'. It’s not evaluated as a regex anymore, but as a string literal.
Also, you use ^ and $, which mean that the string must start with whatever comes after ^ and must end with whatever comes before $. If you just remove those, your regex works fine:
Happy to help, regex can be horribly confusing. By the way, if you really just want to remove two characters (space and comma), I think I’d just chain two lovely brand new .replaceAll() methods, because it’s easier to read (and write): str.replaceAll(',', '').replaceAll(' ', '')