RosettaCodeData/Task/Strip-comments-from-a-string/Kotlin/strip-comments-from-a-string.kts

16 lines
434 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
// 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))
}