fork download
  1. //modified to work with Kotlin 1.0.x
  2. private val keywords = arrayOf("foo", "bar", "spam")
  3. private val pattern = keywords.joinToString(prefix = "(?i)", separator = "|")
  4. private val rx = pattern.toRegex()
  5.  
  6. fun findKeyword(content: String): MutableList<String> {
  7. var result = mutableListOf<String>()
  8. rx.findAll(content).forEach { result.add(it.value) }
  9. return result
  10. }
  11.  
  12. fun main(args: Array<String>) {
  13. println(findKeyword("Some spam and a lot of bar"));
  14. println(arrayOf("foo", "bar", "spam").joinToString(prefix = "(?i)", separator = "|").toRegex())
  15. }
Success #stdin #stdout 0.16s 29224KB
stdin
Standard input is empty
stdout
[spam, bar]
(?i)foo|bar|spam