kotlin / 1.7.0 / api / latest / jvm / stdlib / kotlin.text / -regex / matches-at.html /

matchesAt

Platform and version requirements: JVM (1.7), JS (1.7)
fun matchesAt(input: CharSequence, index: Int): Boolean

Checks if a regular expression matches a part of the specified input char sequence exactly at the specified index.

Unlike matches function, it doesn't require the match to span to the end of input.



fun main(args: Array<String>) {
//sampleStart
val releaseText = "Kotlin 1.5.30 is released!"
val versionRegex = "\\d[.]\\d[.]\\d+".toRegex()
println(versionRegex.matchesAt(releaseText, 0)) // false
println(versionRegex.matchesAt(releaseText, 7)) // true
//sampleEnd
}

Exceptions

IndexOutOfBoundsException - if index is less than zero or greater than the length of the input char sequence.

© 2010–2022 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-regex/matches-at.html