# Aufgabe 1: Bestimme, wie viele Buchstaben, die URL des dfde-Unterforums "Softwareentwicklung und -paketierung, Scripting" () enthält. Zähle einmal mit und einmal ohne die Angabe des Protokolls ("https"). #' ---------------------------- #' ---------------------------- # Tidyverse laden library(tidyverse) #' ---------------------------- #' ---------------------------- # (Hilfs-)funktionen definieren ## Funktion definieren: Handelt es sich um eine HTTP-Url? is_http_url <- function(string) { if (is.character(string)) { string %>% stringr::str_detect("^https://\\S+\\.\\S+$") %>% return() } else { return(NA) } } ## Funktion definieren: Protokollangabe "http://" bzw. https:// entfernen cut_http <- function(string) { if ((is_http_url(string))) { match_matrix <- string %>% stringr::str_match("^https?://(.*)$") # Die Matches und zur ersten (und in diesem Fall auch einzigen) Gruppe (Teilausdruck) befinden sich in match_matrix[2]. return(match_matrix[2]) } else { return(NA) } } #' ---------------------------- #' ---------------------------- # URL zum Forum "Softwareentwicklung und -paketierung, Scripting" im Workspace speichern url_dfde_skripting <- "https://debianforum.de/forum/viewforum.php?f=34" #' ---------------------------- #' ---------------------------- # Buchstaben (inklusive http bzw. https) zählen : if (is_http_url(url_dfde_skripting)) { url_dfde_skripting %>% str_count(pattern = "[:alpha:]") } else { print(NA) } #' ---------------------------- #' ---------------------------- # Buchstaben (abzüglich http bzw. htpps) zählen: url_dfde_skripting %>% cut_http() %>% str_count(pattern = "[:alpha:]") #