Kotlin Regex named groups support

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

Does Kotlin have support for named regex groups?

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

2条回答
  •  生来不讨喜
    2021-02-18 23:31

    As of Kotlin 1.0 the Regex class doesn't provide a way to access matched named groups in MatchGroupCollection because the Standard Library can only employ regex api available in JDK6, that doesn't have support for named groups either.

    If you target JDK8 you can use java.util.regex.Pattern and java.util.regex.Matcher classes. The latter provides group method to get the result of named-capturing group match.

提交回复
热议问题