-2

Hi just trying to understand how to interpret [^.]+ below. I read it as 'match for not (a space or any character), repeated 1+ times. It logically seems the ^ shouldn't be necessary to me. Please clarify, thanks!

numbers = c("one", "three", "four", "five", "six", "seven", "eight", "nine", "ten")
numbers_match = str_c("(", str_c(numbers, collapse = "|"), ") [^ .]+")
has_number <- str_subset(sentences, numbers_match)
str_extract(has_number, numbers_match) %>% head(10)
redsky
  • 37
  • 5

1 Answers1

3

. does not mean "any character" inside [], it's just a literal dot. So [^ .] means "not a space or dot".

sepp2k
  • 341,501
  • 49
  • 643
  • 658