Skip to content

Instantly share code, notes, and snippets.

@kastoestoramadus
Last active September 1, 2016 13:59
Show Gist options
  • Save kastoestoramadus/222197419f52e497061ae9f2a081b85e to your computer and use it in GitHub Desktop.
Save kastoestoramadus/222197419f52e497061ae9f2a081b85e to your computer and use it in GitHub Desktop.
Replace all numbers with that number of '?':
java like:
import java.util.regex.Pattern
val NKasString = "?"
val p = Pattern.compile("[0-9]+")
val m = p.matcher("\"a2a12a2\"")
val sb = new StringBuffer()
while (m.find()) {
val found = m.group()
m.appendReplacement(sb, NKasString * found.toInt)
}
m.appendTail(sb)
println(sb.toString())
scala like:
println(
"[0-9]+".r.replaceAllIn(
"\"a2a12a2\"", m => NKasString * m.group(0).toInt)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment