# single
# combination
words[str_detect(words, "^x") | str_detect(words, "x$")]
# single
str_view(words, "^[aiueo].*[^aiueo]$", match = TRUE)
# combination
words[str_detect(words, "^[aiueo]") & str_detect(words, "[^aiueo]$")]
# single
# combination
words[str_detect(words, "a") & str_detect(words, "i") & str_detect(words, "u") &
str_detect(words, "e") & str_detect(words, "o")]
df <- tibble(
word = words
)
df <- df %>% mutate(number = str_count(word, "[aiueo]"), prop = number / str_length(word))
# highest number
df %>% filter(number == max(df$number))
## # A tibble: 8 x 3
## word number prop
## <chr> <int> <dbl>
## 1 appropriate 5 0.455
## 2 associate 5 0.556
## 3 available 5 0.556
## 4 colleague 5 0.556
## 5 encourage 5 0.556
## 6 experience 5 0.5
## 7 individual 5 0.5
## 8 television 5 0.5
# prop
df %>% filter(prop == max(df$prop))
## # A tibble: 1 x 3
## word number prop
## <chr> <int> <dbl>
## 1 a 1 1
color <- c("red", "orange", "yellow", "green", "blue", "purple")
color_match <- str_c(color, collapse = "|")
str_extract(sentences, "^[a-zA-Z]+")
str_extract_all(sentences, "[a-zA-Z]+ing")
str_extract_all(sentences, "[a-zA-Z]{3,}s")
sentences %>%
str_subset("(one | two | three | four | five | six | seven | eight | nine | ten)([^ ]+)") %>%
str_extract("(one | two | three | four | five | six | seven | eight | nine | ten)([^ ]+)")
## [1] "one over" " seven books" " two met" " two factors"
## [5] "one and" " three lists" " seven is" " two when"
## [9] "one floor." "one with" "one war" " tender"
## [13] "one button" " six minutes." "one in" "one like"
## [17] " two shares" " two distinct" "one costs" " two pins"
## [21] " five robins." " four kinds" "one rang" " tenth"
## [25] " three story" "one wall." " tent," " tent"
## [29] " three inches" " six comes" " tender" "one before"
## [33] " tender" " three batches" " two leaves."
sentences %>%
str_subset("([A-Za-z]+)'([A-Za-z]+)") %>%
str_extract("([A-Za-z]+)'([A-Za-z]+)")
## [1] "It's" "man's" "don't" "store's" "workmen's"
## [6] "Let's" "sun's" "child's" "king's" "It's"
## [11] "don't" "queen's" "don't" "pirate's" "neighbor's"
x <- c("a/b/c/d/e")
str_replace_all(x, "\\/", "\\\\") %>% writeLines()
## a\b\c\d\e
x <- c("AA", "BB", "CC")
str_replace_all(x, c("A" = "a", "B" = "b", "C" = "c")) %>% writeLines()
## aa
## bb
## cc
replace <- words %>% str_replace("(^[A-Za-z])([A-Za-z]*)([A-Za-z]$)", "\\3\\2\\1")
str_view(words, replace,match = TRUE)
x <- "apple, pears, and bananas"
str_split(x, ", and |, ")
## [[1]]
## [1] "apple" "pears" "bananas"
""でやるとピリオドが単語に一部になるが、boundary("word")でやるとピリオドを無視できるx <- "This is a sentence. This is another sentence."
str_split(x, "")[[1]]
## [1] "T" "h" "i" "s" " " "i" "s" " " "a" " " "s" "e" "n" "t" "e" "n" "c"
## [18] "e" "." " " "T" "h" "i" "s" " " "i" "s" " " "a" "n" "o" "t" "h" "e"
## [35] "r" " " "s" "e" "n" "t" "e" "n" "c" "e" "."
x <- c("a\\b", "ab")
# regex()
str_subset(x, regex("\\\\"))
## [1] "a\\b"
# fixed()
str_subset(x, fixed("\\"))
## [1] "a\\b"
sentences %>% str_extract_all(boundary("word")) %>% unlist() %>% str_to_lower() %>%
as_tibble() %>% set_names("words") %>% group_by(words) %>% summarise(n = n()) %>%
arrange(desc(n)) %>% head(5)
## Warning: Calling `as_tibble()` on a vector is discouraged, because the behavior is likely to change in the future. Use `tibble::enframe(name = NULL)` instead.
## This warning is displayed once per session.
## # A tibble: 5 x 2
## words n
## <chr> <int>
## 1 the 751
## 2 a 202
## 3 of 132
## 4 to 123
## 5 and 118