Home>

I'd like to write a regular expression for a string that can be used to enter emails separated by commas.
The regular expression for one email is

/\ A (?<local>((a-zA-Z0-9.! # $%&'* + \/=? ^ _ `{|} ~-]) +) @ (?<domain>([a-zA-Z0-9 _-]) + ([a-zA-Z0-9 ._-] +) +) \ z/
I wrote

, but I didn't know how to write the comma separator.
Can you tell me if there is any good way?

[email protected],<<is NG
[email protected]<<is OK
a @ xx.com, b @ xx.com<<is OK
a @ xx.com, b @ xx.com,<<is NG
  • Answer # 1

    /\ A (?: email regular expression) (?:, email regular expression) * \ z/

  • Answer # 2

    I think that it is certain to apply pattern matching to each of the decomposed items with a comma instead of trying to clean up with a regular expression.