diff --git a/libraries/stdlib/common/src/kotlin/TextH.kt b/libraries/stdlib/common/src/kotlin/TextH.kt index 46c9a4709f7..da9ecc92140 100644 --- a/libraries/stdlib/common/src/kotlin/TextH.kt +++ b/libraries/stdlib/common/src/kotlin/TextH.kt @@ -23,6 +23,7 @@ expect class Regex { * * @return An instance of [MatchResult] if the input matches this [Regex] at the specified [index] or `null` otherwise. * @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of the [input] char sequence. + * @sample samples.text.Regexps.matchAt */ @SinceKotlin("1.5") @ExperimentalStdlibApi @@ -35,6 +36,7 @@ expect class Regex { * Unlike [matches] function, it doesn't require the match to span to the end of [input]. * * @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of the [input] char sequence. + * @sample samples.text.Regexps.matchesAt */ @SinceKotlin("1.5") @ExperimentalStdlibApi diff --git a/libraries/stdlib/samples/test/samples/text/regex.kt b/libraries/stdlib/samples/test/samples/text/regex.kt index 1479baf0bcd..4fd5e3f59c9 100644 --- a/libraries/stdlib/samples/test/samples/text/regex.kt +++ b/libraries/stdlib/samples/test/samples/text/regex.kt @@ -64,4 +64,20 @@ class Regexps { assertPrints(mixedColor, "brown&blue") } + + @Sample + fun matchesAt() { + val releaseText = "Kotlin 1.5.30 is released!" + val versionRegex = "\\d[.]\\d[.]\\d+".toRegex() + assertPrints(versionRegex.matchesAt(releaseText, 0), "false") + assertPrints(versionRegex.matchesAt(releaseText, 7), "true") + } + + @Sample + fun matchAt() { + val releaseText = "Kotlin 1.5.30 is released!" + val versionRegex = "\\d[.]\\d[.]\\d+".toRegex() + assertPrints(versionRegex.matchAt(releaseText, 0), "null") + assertPrints(versionRegex.matchAt(releaseText, 7)?.value, "1.5.30") + } } \ No newline at end of file