matchAt

expect fun matchAt(input: CharSequence, index: Int): MatchResult?(source)

Attempts to match a regular expression exactly at the specified index in the input char sequence.

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

Since Kotlin

1.7

Return

An instance of MatchResult if the input matches this Regex at the specified index or null otherwise.

Throws

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

Samples


fun main() { 
   //sampleStart 
   val releaseText = "Kotlin 1.5.30 is released!"
val versionRegex = "\\d[.]\\d[.]\\d+".toRegex()
println(versionRegex.matchAt(releaseText, 0)) // null
println(versionRegex.matchAt(releaseText, 7)?.value) // 1.5.30 
   //sampleEnd
}
actual fun matchAt(input: CharSequence, index: Int): MatchResult?(source)

Since Kotlin

1.7
actual fun matchAt(input: CharSequence, index: Int): MatchResult?(source)

Since Kotlin

1.7
actual fun matchAt(input: CharSequence, index: Int): MatchResult?(source)

Since Kotlin

1.7