You should look into matching groups in Regex. They can be used to get specific parts of a regular expression after matching. For more info you can read this. For your use-case you can use the following Regex:
\/openPage\/([^\/]+)\/([^\/]+)

Debuggex Demo
And here's how you can do that in Kotlin:
val regex = "\\/openPage\\/([^\\/]+)\\/([^\\/]+)".toRegex()
val match = regex.matchEntire("/openPage/ABC/XYZ")
val category = match?.groups?.get(1)?.value
val subCategory = match?.groups?.get(2)?.value
This way you will have your category and subCategory as String?.
(and).