Generating String Arrays based on regular expression on the input String Array

User_Info:Array(“Brian McNamee (Canada) 16th October 2015”, “Claudia Stanzani 18th September 2009”, …)

Expecting Output: Array(“Brian McNamee”, “Canada”, “16th October 2015”)
Array(“Claudia Stanzani”, “”, “18th September 2009”)

How I am trying:

val pattern="(.+)\\((.+)\\)(.+)".r //pattern variable accepts all the RDDs that contain (<country>)
val default_pattern="(.+)\\s(.+)".r //default pattern variable marking the place country column column empty


 val User_profiles= User_Info.map{
         | case pattern(name, country, year) => (name, country, year)
         | case default_pattern(name, "", year) =>(name, "", year)}

However, I receive matchError. What is the problem that I might be facing? Thank you in advance

Well, offhand the usage of default_pattern looks pretty suspicious – in the case you are declaring it with three parameters, but it only has two capturing groups. That’s probably illegal right there…

1 Like