LoginSignup
3
3

More than 5 years have passed since last update.

Swift2.0 文字列を正規表現で置換するコード

Last updated at Posted at 2015-11-26

Swift2.0で、文字列を正規表現で数字のみに置換するコード

RegExp.swift
var str:String = "1s2Hd34G"
str = str.stringByReplacingOccurrencesOfString("\\D", withString: "$1", options: NSStringCompareOptions.RegularExpressionSearch, range: nil)

// 1234
print(str)
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3