How to use scala function to match error message with a Regex pattern

This function needs to take a given error message, match it to a Regex pattern and return either a prescribed error message or a None

I built the below function where Regex values are preset and the error message = exMess
I know that regex pattern matches if I use exReg.findFirstIn(exMess), but otherwise the match statement only returns None and does not return any of the matching error messages

Intellij is not showing any error that would explain what is wrong

How do I need to handle the Match statement so that it can take the error message, match it with the specific Regex pattern and return a string or None

where exMess = "parseR.TokenException: at line 1"
 

def exceptionBasicRow(exMess: String): Option[String] = {
    val exReg: Regex = ("parser[R,I,N].TokenException: at line 1").r
    val exReg2: Regex = ("parser[R,I,N].ParseException: at line 1").r
    val exReg3: Regex = ("parser[R,I,N].ParseException: at line 1").r


    val error: Option[String] = exMess match {
      case exReg(_) =>
        Option(
          "There is a exReg error")
      case exReg2(_) =>
        Option(
          "There is a exReg2 error")
      case exReg3(_) =>
        Option(
          "There is a exReg3 error")
      case _ => None
    }
    error
 }

I also tried the following syntax, but findFirstIn does not seem accessible from inside the Match statement (colored red)

exMess match{
   case exReg.findFirstIn(exMess)  => print("Error Message")
}

Read more here: Source link