Kotlin Regex named groups support

后端 未结 2 1685
天命终不由人
天命终不由人 2021-02-18 22:57

Does Kotlin have support for named regex groups?

Named regex group looks like this: (?...)

2条回答
  •  走了就别回头了
    2021-02-18 23:34

    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+?)(?\d+)""".toRegex().matchEntire("area51")!!.groups["num"]!!.value
    

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

提交回复
热议问题