Reputation: 63415
I'd like to know which is the simplest and most elegant way to process a text file with email addresses in it and extract them using Scala.
Upvotes: 1
Views: 915
Reputation: 63415
Here is my own attempt at it:
scala> import scala.io.Source.fromFile
scala> val r = """(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b""".r
scala> fromFile("./mails").getLines.flatMap { r.findAllIn _ }.toList
res29: List[String] = List([email protected], [email protected], [email protected])
Upvotes: 3