Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
惯用Kotlin正则表达式_Kotlin - Fatal编程技术网

惯用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

有没有一种更好看的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.toIntOrNull()
} ?: 90

我最好的选择是不使用destructured,而是使用

val matchResult = "(\\d+) rows; (\\d+) columns".toRegex(RegexOption.MULTILINE).find(output)
return matchResult?.groupValues?.get(2)?.toIntOrNull() ?: 80