Matthieu K
Matthieu K

Reputation: 25

Regex for email firstname.lastname

I'm looking to find email address that only match the pattern [email protected] in Scala / Spark

My issue is that "." is used in Scale regex for "Matches any single character except newline"

I tried with \\. but doesn't match as well

Here is my code:

val emailTest = "[email protected]"
if (emailTest.matches("[A-Za-z]+\\.[A-Za-z]+@[A-Za-z0-9.-]"))
  println("ok")
else
  println("nok")

Thanks for your help

Matthieu

Upvotes: 0

Views: 1312

Answers (1)

Tim
Tim

Reputation: 27356

The . is fine, but you are only looking for one character after the @. Add a + to fix this:

"[A-Za-z]+\\.[A-Za-z]+@[A-Za-z0-9.-]+"

Upvotes: 3

Related Questions