Computer scienceProgramming languagesKotlinAdditional instrumentsRegex

MatchResult and capturing groups

Variable type

Report a typo

Imagine you're working with this Kotlin code:

val regex = """(?<hours>\d{2}):(?<minutes>\d{2})""".toRegex()
val input = "The meeting starts at 09:45 and ends at 17:30."

Match each variable to the right type.

Match the items from left and right columns
val x = regex.find(input)!!
val y = x.groups
val z = x.value
val m = x.groups["minutes"]!!
val n = x.range
MatchGroupCollection
MatchGroup
String
MatchResult
IntRange

Create a free account to access the full topic