Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created January 11, 2015 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shigemk2/ff237e2bbfdfd19c4ac3 to your computer and use it in GitHub Desktop.
Save shigemk2/ff237e2bbfdfd19c4ac3 to your computer and use it in GitHub Desktop.
val address = "123 Main Street".replaceAll("[0-9]", "x")
println(address) // xxx Main Street
val regex2 = "[0-9]".r
val newAddress = regex2.replaceAllIn("123 Main Street", "x")
println(newAddress) // xxx Main Street
val result2 = "123".replaceFirst("[0-9]", "x")
println(result2) // x23
val regex3 = "H".r
val result3 = regex3.replaceFirstIn("Hello world", "J")
println(result3) // Jello world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment