I have a regular expression originally used in python to extract 2 strings from a scraped HTML page : vars+kaynaklar.*?urls*:s*"([^"]+)"s*,s*datas*:s*'([^']+)
This works fine in Python but not in Objective-C/Swift.
This is the Swift 2.0 code I'm using to find the results:
do {
let regexString = "var\s+kaynaklar.*?url\s*:\s*"([^"]+)"\s*,\s*data\s*:\s*'([^']+)"
let regex = try NSRegularExpression(pattern: regexString, options: [])
let nsString = text as NSString
let results = regex.matchesInString(text,
options: [], range: NSMakeRange(0, nsString.length))
return results.map { nsString.substringWithRange($0.range)}
} catch let error as NSError {
print("invalid regex: (error.localizedDescription)")
return []
}
And this is an example of the JS being checked inside the HTML looks like :
var kaynaklar = [];
jQuery.ajax({
type:"POST",
url:"/service/part",
data:'id=31398',
success:function(a){
if(a=="hata")
{
jQuery("#player").html("<br><br><font style='color:white;'>Video kayna?? silinmi? lütfen sol üstten Kaynak butonuna t?klayarak farkl? bir kaynak deneyin.</font>")
}
else
{
for (var i = 1; i < 6; i++) {
if(a["videolink"+i])
{
kaynaklar.push({"file":a["videolink"+i], "label":a["videokalite"+i],"type":"mp4"});
}
}
video_loader();
}
},
error:function(){
jQuery("#player").html("<br><br><font style='color:white;'>Video yüklenirken bir hata olu?tu lütfen sayfay? yenileyip tekrar deneyin veya farkl? bir kaynak deneyin.</font>")
}
})
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…