In JavaScript, there's a regex function: RegExp test()
which gets used a bit like this:
new RegExp('/regex/').test('string to match')
What this does is it tests for a match in a string. If it finds a match, it returns true, otherwise it returns false.
But I can't seem to find an equivalent on Kotlin, Android. Does anyone know if there's something like this or similar on Kotlin?
CodePudding user response:
You can use the contains
extension on CharSequence:
"string to match".contains(Regex("regex"))
Or the containsMatchIn
method on Regex:
Regex("regex").containsMatchIn("string to match")