惯用Kotlin正则表达式
有没有一种更好看的Kotlin正则表达式与解构匹配惯用Kotlin正则表达式,kotlin,Kotlin,有没有一种更好看的Kotlin正则表达式与解构匹配 val text = """ a 10 rows; 120 columns b """ val columns = "(\\d+) rows; (\\d+) columns".toRegex(RegexOption.MULTILINE).find(text)?.destructured?.let { (height, width) -> width.toIntOrNul
val text = """
a
10 rows; 120 columns
b
"""
val columns = "(\\d+) rows; (\\d+) columns".toRegex(RegexOption.MULTILINE).find(text)?.destructured?.let { (height, width) ->
width.toIntOrNull()
} ?: 90
我最好的选择是不使用destructured,而是使用
val matchResult = "(\\d+) rows; (\\d+) columns".toRegex(RegexOption.MULTILINE).find(output)
return matchResult?.groupValues?.get(2)?.toIntOrNull() ?: 80