fork(1) download
  1. object Main extends App {
  2. val rPat="""\b(R\d{4})\b""".r.unanchored
  3. val pPat="""\b(P\.\d{2}\.\d{2}\.\d{2})\b""".r.unanchored
  4.  
  5. val matcher= (s:String) => s match {case pPat(el)=> println(el) // print the P.25.01.25
  6. case rPat(el)=>println(el) // print R0100
  7. case _ => println("no match")
  8. }
  9.  
  10. val pSt=" P.25.01.21 - Hello whats going on?"
  11. matcher(pSt)
  12. val pSt2_bad=" CP.2334565.01124.212 - Hello whats going on?"
  13. matcher(pSt2_bad)
  14. val rSt= "R0010 test test 3,870"
  15. matcher(rSt)
  16. val rSt2_bad = "CSR00105 test test 3,870"
  17. matcher(rSt2_bad)
  18. }
Success #stdin #stdout 0.36s 4382720KB
stdin
Standard input is empty
stdout
P.25.01.21
no match
R0010
no match