美文网首页
2019-12-26

2019-12-26

作者: 牛1688 | 来源:发表于2019-12-26 17:42 被阅读0次

提取指定字符串的指定格式内容
        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  {

        }

    }

相关文章

网友评论

      本文标题:2019-12-26

      本文链接:https://www.haomeiwen.com/subject/uajloctx.html