regex - How to extract valid email from larger string in Scala -


My Scala Version 2.7.7

I try to remove an email address from a bigger address I am here. The string is not automatically a format. I have the code:

  import scala.util.matching.Regex import scala.util.matching._val Reg = "" "\ b [A-Z0-9 ._% + -] + @ [A.J-0-9 .-] + \. [AG] {2,4} \ B "" ". RO "My name is Joe: joe@gmail.com" match {Case Rege (E) => Println ("Match:" + E) Case _ = & gt; Println ("unsuccessful")}  

Regex passes in regxbilder but does not pass to Scala. Apart from this, if there is any way that is done without any reggae, which will be okay. Thanks!

As Allen Moore pointed out, you get the (? I) pattern To make this case insensitive to start, also keep in mind that the use of Regex matches the entire string directly. If you want to find one within a large string, you can call findFirstIn () or use the same method of Regex.

  val reg = "" (? I) \ b [A-Z0- 9 ._% + -] + @ [A-Z0-9 .-] + \. [AGED ] {2,4} \ b "". Before finding the RR, "Yo my name is: joe@gmail.com" match {case something (email) => Println ("match:" + email) case No = & gt; Println ("unsuccessful")}  

Comments