Skip to main content
1 of 8
Ky -
  • 407
  • 2
  • 15

Can this sanitization regex be better?

/((([\w -]+)|("[\w -]+"))( *, *)?)+/

http://refiddle.com/18ql

I'm trying to use a regex to sanitize a user input for a list of fonts. The above one seems to work nicely, but also feels a bit long and redundant, having two [\w -]*s, and allowing a trailing comma, and possibly stuff I can't see. Can this be more efficient (smaller, less redundant, more secure)?


Also, I think an input, input-handling, andor input-sanitization tag would be good additions to this SE.

Ky -
  • 407
  • 2
  • 15