Podobało mi się rozwiązanie Stefana Henze, ale przyniosło 34,56. Jest zbyt ogólny i mam nieprzetworzony html. Istnieją 4 kotwice dla adresu URL;
www,
http: \ (i co),
. po którym następują litery, a następnie /,
lub litery. i jeden z nich: https://ftp.isc.org/www/survey/reports/current/bynum.txt .
Wykorzystałem wiele informacji z tego wątku. Dziękuję wam wszystkim.
"(((((http|ftp|https|gopher|telnet|file|localhost):\\/\\/)|(www\\.)|(xn--)){1}([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=
Powyższe rozwiązuje prawie wszystko z wyjątkiem ciągu znaków, takich jak „eurls: www.google.com, facebook.com, http: //test.com/”, który zwraca jako pojedynczy ciąg. Tbh idk, dlaczego dodałem gopher itp. Sprawdzaj kod R.
if(T){
wierdurl<-vector()
wierdurl[1]<-"https://JP納豆.例.jp/dir1/納豆 "
wierdurl[2]<-"xn--jp-cd2fp15c.xn--fsq.jp "
wierdurl[3]<-"http://52.221.161.242/2018/11/23/biofourmis-collab"
wierdurl[4]<-"https://12000.org/ "
wierdurl[5]<-" https://vg-1.com/?page_id=1002 "
wierdurl[6]<-"https://3dnews.ru/822878"
wierdurl[7]<-"The link of this question: /programming/6038061/regular-expression-to-find-urls-within-a-string
Also there are some urls: www.google.com, facebook.com, http://test.com/method?param=wasd
The code below catches all urls in text and returns urls in list. "
wierdurl[8]<-"Thelinkofthisquestion:/programming/6038061/regular-expression-to-find-urls-within-a-string
Alsotherearesomeurls:www.google.com,facebook.com,http://test.com/method?param=wasd
Thecodebelowcatchesallurlsintextandreturnsurlsinlist. "
wierdurl[9]<-"Thelinkofthisquestion:/programming/6038061/regular-expression-to-find-urls-within-a-stringAlsotherearesomeurlsZwww.google.com,facebook.com,http://test.com/method?param=wasdThecodebelowcatchesallurlsintextandreturnsurlsinlist."
wierdurl[10]<-"1facebook.com/1res"
wierdurl[11]<-"1facebook.com/1res/wat.txt"
wierdurl[12]<-"www.e "
wierdurl[13]<-"is this the file.txt i need"
wierdurl[14]<-"xn--jp-cd2fp15c.xn--fsq.jpinspiredby "
wierdurl[15]<-"[xn--jp-cd2fp15c.xn--fsq.jp/inspiredby "
wierdurl[16]<-"xnto--jpto-cd2fp15c.xnto--fsq.jpinspiredby "
wierdurl[17]<-"fsety--fwdvg-gertu56.ffuoiw--ffwsx.3dinspiredby "
wierdurl[18]<-"://3dnews.ru/822878 "
wierdurl[19]<-" http://mywebsite.com/msn.co.uk "
wierdurl[20]<-" 2.0http://www.abe.hip "
wierdurl[21]<-"www.abe.hip"
wierdurl[22]<-"hardware/software/data"
regexstring<-vector()
regexstring[2]<-"(http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=
regexstring[3]<-"/(?:(?:https?|ftp|file):\\/\\/|www\\.|ftp\\.)(?:\\([-A-Z0-9+&@#\\/
regexstring[4]<-"[a-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]?"
regexstring[5]<-"((http|ftp|https)\\:\\/\\/)?([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=
regexstring[6]<-"((http|ftp|https):\\/\\/)?([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=
regexstring[7]<-"(http|ftp|https)(:\\/\\/)([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=
regexstring[8]<-"(?:(?:https?|ftp|file):\\/\\/|www\\.|ftp\\.)(?:\\([-A-Z0-9+&@#/
regexstring[10]<-"((http[s]?|ftp):\\/)?\\/?([^:\\/\\s]+)((\\/\\w+)*\\/)([\\w\\-\\.]+[^#?\\s]+)(.*)?(#[\\w\\-]+)?"
regexstring[12]<-"http[s:/]+[[:alnum:]./]+"
regexstring[9]<-"http[s:/]+[[:alnum:]./]+" #in DLpages 230
regexstring[1]<-"[[:alnum:]-]+?[.][:alnum:]+?(?=[/ :])" #in link_graphs 50
regexstring[13]<-"^(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$"
regexstring[14]<-"(((((http|ftp|https):\\/\\/)|(www\\.)|(xn--)){1}([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:\\/~+#-]*[\\w@?^=%&\\/~+#-])?)|(([\\w_-]+(?:(?:\\.[\\w_-]+)*))((\\.((org|com|net|edu|gov|mil|int)|(([:alpha:]{2})(?=[, ]))))|([\\/]([\\w.,@?^=%&:\\/~+#-]*[\\w@?^=%&\\/~+#-])?))))(?!(((ttp|tp|ttps):\\/\\/)|(ww\\.)|(n--)))"
regexstring[15]<-"(((((http|ftp|https|gopher|telnet|file|localhost):\\/\\/)|(www\\.)|(xn--)){1}([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:\\/~+#-]*[\\w@?^=%&\\/~+#-])?)|(([\\w_-]{2,200}(?:(?:\\.[\\w_-]+)*))((\\.[\\w_-]+\\/([\\w.,@?^=%&:\\/~+#-]*[\\w@?^=%&\\/~+#-])?)|(\\.((org|com|net|edu|gov|mil|int|arpa|biz|info|unknown|one|ninja|network|host|coop|tech)|(jp|br|it|cn|mx|ar|nl|pl|ru|tr|tw|za|be|uk|eg|es|fi|pt|th|nz|cz|hu|gr|dk|il|sg|uy|lt|ua|ie|ir|ve|kz|ec|rs|sk|py|bg|hk|eu|ee|md|is|my|lv|gt|pk|ni|by|ae|kr|su|vn|cy|am|ke))))))(?!(((ttp|tp|ttps):\\/\\/)|(ww\\.)|(n--)))"
}
for(i in wierdurl){#c(7,22)
for(c in regexstring[c(15)]) {
print(paste(i,which(regexstring==c)))
print(str_extract_all(i,c))
}
}