mit i nur die Links von Webseiten extrahiert werden soll nach dem folgenden Code:Extrakt genaue Links von String Regex in schnellen 2,2
import UIKit
import Foundation
func regMatchGroup(regex: String, text: String) -> [String] {
do {
let regex = try NSRegularExpression(pattern: regex, options: [])
let nsString = text as NSString
let results = regex.matchesInString(text,
options: [], range: NSMakeRange(0, nsString.length))
var internalString = [String]()
for result in results {
for var i = 0; i < result.numberOfRanges; ++i{
internalString.append(nsString.substringWithRange(result.rangeAtIndex(i)))
}
}
return internalString
} catch let error as NSError {
print("invalid regex: \(error.localizedDescription)")
return []
}
}
// USAGE:
let textsearch = "mohamed amine ammach <img alt='http://fb.com' /> hhhhhhhhhhh <img alt='http://google.com' />"
let matches = regMatchGroup("alt='(.*?)'", text: textsearch)
if (matches.count > 0) // If we have matches....
{
for (var i=0;i < matches.count;i++) {
print(matches[i])
}
}
die playgrond druckt die folgenden:
alt='http://fb.com'
http://fb.com
alt='http://google.com'
http://google.com
aber i sind nur zu erhalten versuchen:
http://fb.com
http://google.com
Dose hier jemand mir helfen, dieses Problem zu lösen, werde mir
Ihr Ergebnis ist in ersten Capturing Gruppe – rock321987