Here is some scala matcher code using named groups:
val regex=".*Completed (?<tstamp>[\d]{4}-[\d]{6})/(?<tname>[\w]+) (?<loops>[\d]+)Loops (?<cores>[\d]+)cores (?<mem>[\d]+)mb (?<inrecs>[\d]+)recs (?<nparts>[\d]+)parts (?<xform>[\w]+) (?<action>[\w]+) - duration=(?<duration>[\d]+\.[\d]+) seconds count=(?<outrecs>[\d]+).*"
val rmatch = meta.regex.findFirstMatchIn(line)
The input is:
<03:54:26> Completed 0917-035231/CpuMem 100000000Loops 16cores 128mb 5000000recs 20parts GroupByKey Count - duration=41.408 seconds count=5000000
We can see in the screenshot of the Watch screen for the pattern (third entry) that the first capturing group is named tstamp
. It is properly captured and viewable as
m[atch].group(1)
However it is not accessible within the named group
m[atch].group("tstamp")
There is another SOF question touching on this topic but that is five years old (before Java7 came out with support for named groups): Scala regex Named Capturing Groups
But that one does not address this scenario of scala 2.11 / java8