fork download
  1. import java.util.*
  2.  
  3. fun main(args: Array<String>) {
  4. val text = "This is a %s with %02d whatever"
  5. val rx = """%(\d*[a-z])""".toRegex()
  6. println(text.replace(rx, "<$1/>")) // "This is a <s/> with <02d/> whatever"
  7. println(rx.replace(text) { "<${it.groupValues[1].toUpperCase()}>" })
  8. println(rx.replace(text) { it.groupValues[1].toUpperCase() })
  9. }
Success #stdin #stdout 0.11s 40108KB
stdin
Standard input is empty
stdout
This is a <s/> with <02d/> whatever
This is a <S> with <02D> whatever
This is a S with 02D whatever