Kotlin Regex named groups support

gs_vlad picture gs_vlad · May 7, 2016 · Viewed 8.5k times · Source

Does Kotlin have support for named regex groups?

Named regex group looks like this: (?<name>...)

Answer

Vadzim picture Vadzim · Sep 3, 2016

According to this discussion,

This will be supported in Kotlin 1.1. https://youtrack.jetbrains.com/issue/KT-12753

Kotlin 1.1 EAP is already available to try.


"""(\w+?)(?<num>\d+)""".toRegex().matchEntire("area51")!!.groups["num"]!!.value

You'll have to use kotlin-stdlib-jre8.