How to extract only words with first-letter lowercase from a string in Kotlin

1 Answer

0 votes
fun lowercaseWords(s: String): List<String> {
    return s.split(Regex("\\W+"))
        .filter { it.isNotEmpty() && it[0].isLowerCase() }
}

fun main() {
    val s = "Kotlin java Rust python C CPP nodejs go"

    val result = lowercaseWords(s)

    result.forEach { println(it) }
}



/*
run:

java
python
nodejs
go

*/

 



answered Jan 16 by avibootz

Related questions

...