Paul Woitaschek
05/17/2020, 9:42 AMregex.find(line)?.groupValues?.getOrNull(1)
Is this the correct way to find the first match of a regex result?Arian Stolwijk
05/17/2020, 8:03 PMdestructured
to make it easier?Paul Woitaschek
05/17/2020, 8:36 PMaraqnid
05/18/2020, 6:01 AMval (g) = match.destructured
will assign the first match group to g
. Although that’s not so convenient when you’re starting from an optional match.
regex.find(input)?.let { it.groupValues[1] }
would be what I’d writeMichael de Kaste
05/18/2020, 7:05 AMnkiesel
05/19/2020, 6:41 AMRegex("my \\w+").find("hello my dear friend")?.value
which returns my dear
. W/o that you always would have to have at least one ()
in every regex to get a matched string back