Skip to content

Instantly share code, notes, and snippets.

@y8k
Created February 1, 2018 14:25
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 y8k/4dbb0a32ca3c716458d54b77fec70362 to your computer and use it in GitHub Desktop.
Save y8k/4dbb0a32ca3c716458d54b77fec70362 to your computer and use it in GitHub Desktop.
Convert phone number consist of digits to with dash
let phoneNumber = "01026979999"
// REGEX FOR KOREAN CELL PHONE NUMBER FORMAT
let expression = "(\\d{3})(\\d{\(phoneNumber.count - 7)})(\\d{4})"
let result = phoneNumber.replacingOccurrences(of: expression, with: "$1-$2-$3", options: .regularExpression, range: nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment