RosettaCodeData/Task/Strip-comments-from-a-string/Kotlin/strip-comments-from-a-string.kotlin
2023-07-01 13:44:08 -04:00

15 lines
434 B
Text

// version 1.0.6
val r = Regex("""(/\*.*\*/|//.*$)""")
fun stripComments(s: String) = s.replace(r, "").trim()
fun main(args: Array<String>) {
val strings = arrayOf(
"apples, pears // and bananas",
" apples, pears /* and bananas */",
"/* oranges */ apples // pears and bananas ",
" \toranges /*apples/*, pears*/*/and bananas"
)
for (string in strings) println(stripComments(string))
}