regex – Regular Expression for Multiple Email addresses separated with a single space and not ending with space
two possible approaches
- 1..n emails followed by optional space
- 0..n emails followed by one space plus 1 email followed by no space
the first approach would also match for two emails separated with no space. But as you also have the \b before the space in your regex the validation will be ok with this simpler first approach. Instead of \b {0,1}
you could also write \b ?
^((?:([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})\b {0,1}))+$
or
^((?:([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})\b {1}))*((?:([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})\b)+$
short answer (combined with ideas from other answers)
^(?:[\w.%+-]+@[\w.]+\.[A-Za-z]{2,4}\b ?)+$
Read more here: Source link