oday
03/11/2022, 2:00 PM"ticket-alert/remove/(?<id>.+)/(?<hash>.+)".toRegex()
oday
03/11/2022, 2:00 PMTies
03/11/2022, 2:06 PM"ticket-alert/remove/(?<id>.+)/(?<hash>.+)".toRegex().matchEntire("")
And now you have a MatchResult? which contains your matching groupsTies
03/11/2022, 2:07 PModay
03/11/2022, 2:08 PModay
03/11/2022, 2:08 PMTies
03/11/2022, 2:09 PModay
03/11/2022, 2:31 PMroutes = mapOf(
'/ticket-alert/remove/(?<id>.+)/(?<hash>.+)' to (id, hash) => RemoveTicketAlertByHashLaunchAction(ticketAlertId=id, ticketAlertHash = hash)
)
oday
03/11/2022, 2:31 PModay
03/11/2022, 2:32 PModay
03/11/2022, 2:35 PMnkiesel
03/11/2022, 8:18 PMfun extract(s: String): Map<String, String> {
val regex = "ticket-alert/remove/([^/]+)/([^/]+)".toRegex()
val (id, hash) = regex.matchEntire(s)?.destructured ?: throw IllegalArgumentException()
return mapOf("id" to id, "hash" to hash)
}
nkiesel
03/11/2022, 8:25 PMdata class TicketAlert(val id: String, val hash: String) {
companion object {
val regex = """ticket-alert/remove/([^/]+)/([^/]+)""".toRegex()
fun extract(s: String): TicketAlert {
val (id, hash) = regex.matchEntire(s)?.destructured ?: throw IllegalArgumentException()
return TicketAlert(id, hash)
}
}
}