--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
val pattern = "([aeiou]*)?([^aeiou]*)?".r
pattern.unapplySeq("aaabbb") match {
case Some(Seq(a,b)) => println(s"$a $b")
case _ => println("no match")
}
pattern.unapplySeq returns an Option[List[String]], which you can then map/flatmap or match.
Another alternative, which works better if you want to match multiple patterns:
"aaabbb" match {
case pattern(a,b) => println(s"$a $b")
case _ => println("no match")
}