Q:

Splitting strings separated by a comma and a white space in spark using scala

I am trying to read a text file with the following format
1980, Jan, Wednesday
1982, Feb, Monday
1987, March, Thursday

I tried to separate each string with a comma and a space with the following code:
val line = sc.textFile("file.txt") 
val lineMap = line.map(x => x.split("[,]+"))

But this gives java.lang.ArrayIndexOutOfBoundsException.
How to solve this problem?

A:

TLDR
Use:
val line = sc.textFile("file.txt") 
val lineMap = line.map(x => x.split(",\\s"))

See: https://imgur.com/a/mi1waOa

