question.one <- "My number is 1236534512 but i can also be reached through 2124496571$";
unlist(str_extract_all(question.one, "[0-9]+\\$"));
## [1] "2124496571$"
unlist(str_extract_all(question.one, "\\b[a-z]{1,4}\\b"));
## [1] "is" "but" "i" "can" "also" "be"
my.file <- "My name 1 is myPersonalDetails.txt";
unlist(str_extract_all(my.file, ".*?\\.txt$"));
## [1] "My name 1 is myPersonalDetails.txt"
random.number <- "This is a random abx333/44/333322";
unlist(str_extract_all(random.number, "\\d{2}/\\d{2}/\\d{4}"))
## [1] "33/44/3333"
random.tag <- "<html>Hellow from Arun</html>";
unlist(str_extract_all(random.tag, "<(.+?)>.+?</\\1>"));
## [1] "<html>Hellow from Arun</html>"
unlist(str_extract_all(question.one, "\\d*\\$"));
## [1] "2124496571$"
my.email <- "chunkylover53[at]aol[dot]com";
my.email <- str_replace(my.email, "\\[at\\]", "@");
my.email <- str_replace(my.email, "\\[dot\\]", ".");
The transformed email address : chunkylover53@aol.com
b. What’s wrong in using [[:digit:]] ?
unlist(str_extract_all(my.email, "[[:digit:]]"));
## [1] "5" "3"
unlist(str_extract_all(my.email, "[[:digit:]]+"));
## [1] "53"
unlist(str_extract_all(my.email, "\\D+"));
## [1] "chunkylover" "@aol.com"
unlist(str_extract_all(my.email, "\\d+"));
## [1] "53"