'Filter the list in scala based on the regular expression

I have a list in Scala as below.

val inputList :List[String] = List("Manager","VP", "12/09/2011","Access","10/11/2021 1:51 PM","Agent","Customer Contact date 07/23/2011", "Profile")
inputList: List[String] = List(Manager, VP, 12/09/2011, Access, 10/11/2021 1:51 PM, Agent, Customer Contact date 07/23/2011, Profile)

Now I want to ignore the list elements that only STARTS WITH a date. So when I filter out and print the list I should get it as the below.

Manager
VP
Access
Agent
Customer Contact date 07/23/2011
Profile

I tried as

scala>var finalList = List[String]()

scala> finalList =  inputList.filterNot(r => r.startsWith("[0-9]{1,2}[/][0-9]{1,2}[/][0-9]{4}"))
finalList: List[String] = List(Manager, VP, 12/09/2011, Access, 10/11/2021 1:51 PM, Agent, Customer Contact date 07/23/2011, Profile)

I still see elements starting with date. I tried different regex format as below and still see its not ignoring them. Is the regex I am using has any issue? I tried scala> finalList = inputList.filterNot(r => r.startsWith("\\d{1,2}[/]\\d{1,2}[/]\\d{4}") and still see its not eliminating list elements that begin with date. Can i get some advise...

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source