fork(1) download
  1. object Main extends App {
  2. val COL1 = "COL1"
  3. val COL2 = "COL2"
  4. val COL3 = "COL3"
  5. val COL4 = "COL4"
  6. val COL5 = "COL5"
  7. val reg = """(\w{3,4})-(\w{3})-(\w{3,4})-(\w+)-(\w+)""".r
  8. val dataExtraction: String => Map[String, String] = {
  9. string: String => {
  10. string match {
  11. case reg(col1, col2, col3, col4, col5) =>
  12. Map(COL1 -> col1, COL2 -> col2, COL3 -> col3, COL4 -> col4 ,COL5 -> col5 )
  13. case _ => Map(COL1 -> "", COL2 -> "", COL3 -> "", COL4 -> "" ,COL5 -> "" )
  14. }
  15. }
  16. }
  17. println(dataExtraction("dep-gll-cde3-l4-result"))
  18. println(dataExtraction("cde3-gll-dep-l4-result"))
  19. }
Success #stdin #stdout 0.43s 2181632KB
stdin
Standard input is empty
stdout
Map(COL4 -> l4, COL2 -> gll, COL3 -> cde3, COL1 -> dep, COL5 -> result)
Map(COL4 -> l4, COL2 -> gll, COL3 -> dep, COL1 -> cde3, COL5 -> result)