I have a regular expression
^[a-zA-Z+#-.0-9]{1,5}$
which validates that the word contains alpha-numeric characters and few special characters and length should not be more than 5 characters.
How do I make this regular expression to accept a maximum of five words matching the above regular expression.
^[a-zA-Z+#\-.0-9]{1,5}(\s[a-zA-Z+#\-.0-9]{1,5}){0,4}$Also, you could use for example
[ ]instead of\sif you just want to accept space, not tab and newline. And you could write[ ]+(or\s+) for any number of spaces (or whitespaces), not just one.Edit: Removed the invalid solution and fixed the bug mentioned by unicornaddict.