0

swift 正则表达式匹配替换字符串

miriam created at5 years ago view count: 3096

swift 怎样正则表达式匹配替换字符串?

比如把[email protected] 替换为 root#baidu.com

report
回复
0
let txt = "[email protected]"
let regex = NSRegularExpression(pattern: "([^@\\s]+)@test\\.(\\w+)", options:nil, error: nil)
let newString = regex!.stringByReplacingMatchesInString(txt, options: nil, range: NSMakeRange(0, count(txt)), withTemplate: "[email protected]$2")
println(newString)
5 years ago 回复

Recent search keywords