Scala2.12 Regular Expressions Approach

#1

Hi All,

I’m working on the spark 2.4 scala 2.12 data processing feeds.I need some help on the extract of multiple values in the file pattern.How do we achieve this?.Give me some insights on scala ways.

Need to extract’s the multiple values in the given file name pattern using spark/scala regular expression.please

object Driver {

private val filePattern = xyzabc_source2target_adver_field1 _ ([a-zA-Z0-9]+) field2 _ ([a-zA-Z0-9]+) _ field3 _ ([a-zA-Z0-9]+) _ field4
([a-zA-Z0-9]+) _ field5 _ ([a-zA-Z0-9]+) _ field6 _ ([a-zA-Z0-9]+) _ field7_([a-zA-Z0-9]+)".r

How to get all 7 values like this pattern “([a-zA-Z0-9]+)” from above file regex pattern using scala
and assigned it to the below processing method case class schema fields

def processing(x:Dataset[someData]){

x.map{
e =>

caseClassObject(
Field1 = 1stvalue
Field2 = 2ndvalue
Field3 = 3rdvalue
Field4 = 4thvalue
Field5 = 5thvalue
Field6 = 6thvalue
Field7 = 7thvalue
)
}
}

Thanks
Anbu