import kotlin.text.* import kotlin.collections.* const val regConstructor1 = Regex("pattern").pattern const val regConstructor2 = Regex("pattern", RegexOption.IGNORE_CASE).options.iterator().next().name const val regConstructor3 = Regex("pattern", setOf(RegexOption.IGNORE_CASE, RegexOption.MULTILINE)).options.size const val matchEntire1 = Regex("pat").matchEntire("pat")?.value.toString() const val matchEntire2 = Regex("[abc]").matchEntire("a")?.range?.last.toString() const val matches1 = Regex("str(1)?").matches("str1") const val matches2 = Regex("str(1)?").matches("str2") const val containsMatchIn1 = Regex("[0-9]").containsMatchIn("0") const val containsMatchIn2 = Regex("[0-9]").containsMatchIn("!!0!!") const val containsMatchIn3 = Regex("[0-9]").containsMatchIn("!!p!!") //replace const val replace1 = Regex("0").replace("There are 0 apples", "n") const val replace2 = Regex("(red|green|blue)").replace("Roses are red, Violets are blue") { it.value + "!" } const val replace3 = Regex("(red|green|blue)").replaceFirst("Roses are red, Violets are blue", "REPLACED") const val split = Regex("\\W+").split("Roses are red, Violets are blue").size //find const val find1 = Regex("p").find("p")?.value.toString() const val find2 = Regex("(red|green|blue)").find("Roses are red, Violets are blue")?.groups?.size.toString() const val find3 = Regex("(red|green|blue)").find("Roses are red, Violets are blue")?.destructured?.component1().toString() const val find4 = Regex("(red|green|blue)").find("Roses are red, Violets are blue")?.next()?.value.toString() const val find5 = Regex("(red|green|blue)").find("Roses are red, Violets are blue", 15)?.value.toString() const val find6 = Regex("(red|green|blue)").findAll("Roses are red, Violets are blue").iterator().next()?.value.toString() const val find7 = Regex("(red|green|blue)").findAll("Roses are red, Violets are blue").iterator().next()?.next()?.value.toString() const val find8 = Regex("(red|green|blue)").findAll("Roses are red, Violets are blue").iterator().next()?.next()?.next()?.value.toString() //companion const val fromLiteral = Regex.fromLiteral("[a-z0-9]+").pattern const val escape = Regex.escape("[a-z0-9]+") const val escapeReplacement = Regex.escapeReplacement("[a-z0-9]+")