How to extract valid email from larger string in Scala
Posted
by luigi-prog
on Stack Overflow
See other posts from Stack Overflow
or by luigi-prog
Published on 2010-05-17T00:08:59Z
Indexed on
2010/05/17
0:50 UTC
Read the original article
Hit count: 334
My scala version 2.7.7
Im trying to extract an email adress from a larger string. the string itself follows no format. the code i've got:
import scala.util.matching.Regex
import scala.util.matching._
val Reg = """\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b""".r
"yo my name is joe : [email protected]" match {
case Reg(e) => println("match: " + e)
case _ => println("fail")
}
the Regex passes in RegExBuilder but does not pass for scala. Also if there is another way to do this without regex that would be fine also. Thanks!
© Stack Overflow or respective owner