2019-12-26
提取指定字符串的指定格式内容
let phoneStr = "创建时间 1894512345678"
letphoneRegex ="\\d{6,13}"
do{
letregular =try!NSRegularExpression.init(pattern: phoneRegex, options: .allowCommentsAndWhitespace)
letresult = regular.matches(in: phoneStr, options: [], range:NSRange.init(location:0, length: phoneStr.count))
for (i, match)inresult.enumerated(){
letss = match.numberOfRanges
forindexin0...ss {
letrange = match.range(at: index)
letnewPhoneStr = (phoneStrasNSString).substring(with: range)
letphone ="telprompt://"+(phoneStrasString)
ifUIApplication.shared.canOpenURL(URL(string: phone)!) {
UIApplication.shared.openURL(URL(string: phone)!)
}
///可能匹配出多条,我只要一条
return
}
}
}catch {
}
}