-2

I have the following regex set up to accept words and some special characters:

const regex = /^[\w\-'.,?\/()\[\]!&\s]+$/;

I want to extend this to also include the range of special characters in Spanish: ñáéíóú

I found this answer which provides a regex for all special chars, but I'm not sure how to incorporate this kind of solution into my already existing regex.

Alk
  • 4,725
  • 8
  • 40
  • 96

1 Answers1

1

You can simply add those characters to the class you already have in your regex:

const regex = /^[\wñáéíóú\-'.,?\/()\[\]!&\s]+$/;

It is not needed to add the u modifier.

NB: it is not really necessary to escape the [ character inside a character class.

trincot
  • 263,463
  • 30
  • 215
  • 251