oday
03/11/2022, 2:00 PM"ticket-alert/remove/(?<id>.+)/(?<hash>.+)".toRegex()
Ties
03/11/2022, 2:06 PM"ticket-alert/remove/(?<id>.+)/(?<hash>.+)".toRegex().matchEntire("")
And now you have a MatchResult? which contains your matching groupsoday
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)
)
nkiesel
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)
}
data 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)
}
}
}