func URLRegex(text: String)
{
do{
let pattern = "\\bhttp?://.*?(jpg|png)"
let dataDetector = try NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.CaseInsensitive)
let res = dataDetector.matchesInString(text, options: NSMatchingOptions(rawValue: 0), range: NSMakeRange(0, text.characters.count))
for checkingRes in res
{
let str = (text as NSString).substringWithRange(checkingRes.range)
print(str)
self.dataArray.append(str)
}
print(self.dataArray)
self.collection.reloadData()
}catch
{
print(error)
}
}
swift 获取网页中图片地址的正则表达式
最新推荐文章于 2022-07-08 06:35:44 发布