下面是电子邮件 id 的正则表达式,最小 10 和最大 30 字符长度。
scala> val email4 = """[([\w\.!#$%&*+/=?^_`{|}~-]+)@([\w]+)([\.]{1}[\w]+)+]{10,30}""".r
email4: scala.util.matching.Regex = [([\w\.!#$%&*+/=?^_`{|}~-]+)@([\w]+)([\.]{1}[\w]+)+]{10,30}
scala> email4.pattern.matcher("ar@g.com").matches
res19: Boolean = false
scala> email4.pattern.matcher("ar@gmail.com").matches
res20: Boolean = true
scala> email4.pattern.matcher("ar1234567890@gmail1234567890.com").matches
res21: Boolean = false
scala> email4.pattern.matcher("ar1234567890@gmail123456780.com").matches
res22: Boolean = false
scala> email4.pattern.matcher("ar1234567890@gma.com").matches
res23: Boolean = true
scala> email4.pattern.matcher("ar1234567890@gmghfjdfcga.com").matches
res24: Boolean = true
scala> email4.pattern.matcher("ar1234567890@gmghfjdfcga1.com").matches
res25: Boolean = true
scala> email4.pattern.matcher("ar1234567890@gmghfjdfcga111.com").matches
res26: Boolean = false
scala> email4.pattern.matcher("ar1234567890@gmghfjdfcga11.com").matches
res27: Boolean = true