Home > Software design >  regex to match list of characters and specific words
regex to match list of characters and specific words

Time:11-20

I'm trying to create a regex username whitelist allowing a specific list of characters and specific list of words (html entities)

This is the current regex that I have ^[a-zA-Z0-9 ,.@\|:()\[\]%_\/'-] $ but I would also want to allow & but I have no idea how to join the two

https://regex101.com/r/t0GmKe/1/

CodePudding user response:

Use an alternation:

^(?:[a-zA-Z0-9 ,.@\|:()\[\]%_\/'-]|&) $

This simply says to match a character from your current character class or &, one or more times.

  • Related