Does anyone know why this code returns false? ```f...
# announcements
p
Does anyone know why this code returns false?
Copy code
fun main() {
    val str = "123test123"
    val matches = Regex("""test""", RegexOption.MULTILINE).matches(str)
    println(matches)
}
Posted in #kotlin-native
g
because it doesn’t match the entire input
p
Does Regex work differently in Kotlin? I know that this matches in JavaScript for example. How can I get this to match in Kotlin?
g
maybe you can try
containsMatchIn
instead of
matches
i
Try
regex in str
, it's the same as
containsMatchIn
but in operator form.
👍 4
😮 6
2
p
Thanks, this works 👍
n
And yes: JS and Java/Kotlin regex behavior (and syntax) is different. JS "match" is similar to Kotlin "find":
Regex("test").find("123test456")?.groupValues