I have a common pattern where I want to operate on a string like abckey123 where I want to clear the string before key but also remove the key.
Is there a commonly accepted way to do this? Or even better a way to make this a single method call on all string objects?
Ideas:
item.replaceBefore("key", "").replace("key", "")
item.split("key").last()
key, "123abckey123", or allkey"123'"""(.*?)?key(\d+)""".toRegex().findAll(yourInputString).map { it.destructured }.forEach { (firstPart, secondPart) -> println("$firstPart -> $secondPart") }... In this example the regex extracts everything before the lastkeyinto group 1 and every digit afterkeyto group 2. So with an input ofsomekey123it would printsome -> 123and withsomekeykey123it would printsomekey -> 123.