Add Regex matchAt samples
This commit is contained in:
committed by
Space
parent
d7b10f31b4
commit
5004735366
@@ -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
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user