fork download
  1. object Main extends App {
  2. val emp: List[String] = List("customer_bal_history_1_36","customer_bal_history_1_36_1","customer_bal_history_1_36_2","customer_bal_history_1_36_3","customer_credit_history_37_72_1","customer_credit_history_37_72_2","customer_credit_history_37_72_3","employee_1", "employee_10", "address","pincode","domain_1","domain_2","vehicle_1","vehicle_2","vendor_account_1","vendor_account_2")
  3. val pattern = """^[^\d_]*_[^\d_]*_\D*_""".r
  4. val res = emp.foldLeft(Map[String, List[String]]()){ case (acc, name) =>
  5. pattern.findFirstMatchIn(name) match {
  6. case Some(ns) => acc + (ns.group(0) -> (name :: acc.getOrElse(ns.group(0), Nil)))
  7. case _ => acc
  8. }
  9. }.values.toList
  10.  
  11. println(res)
  12.  
  13. }
Success #stdin #stdout 0.62s 73696KB
stdin
Standard input is empty
stdout
List(List(customer_bal_history_1_36_3, customer_bal_history_1_36_2, customer_bal_history_1_36_1, customer_bal_history_1_36), List(customer_credit_history_37_72_3, customer_credit_history_37_72_2, customer_credit_history_37_72_1))