让字符串只保留数字、字母和汉字
let info = "2\n34`2\t3!@#$%^&*()张5*2三"
//^的含义是取反
let r = try! NSRegularExpression(pattern: "[^a-zA-Z0-9\u{4e00}-\u{9fa5}]", options: .allowCommentsAndWhitespace)
let newInfo = r.stringByReplacingMatches(in: info, options: .reportProgress, range: NSRange(location: 0, length: info.count), withTemplate: "")
print(info)
print("-----------------------")
print(newInfo)
过滤html标签和换行符
//正则表达式为
<[^>]*>|\\n
// html的正则为
<[^>]*>
// 换行的正则为
\\n
// | 代表拼接规则的含义