I am having trouble with [:punct:] in R regex. To my mind pat1
and pat2
, on this narrow example, should produce identical results.
library(stringr)
test <- " <= 17 "
pat1 <- "[[:punct:]]+"
str_extract(test, pat1)
# [1] NA
pat2 <- "[[\\=\\<\\>]]+"
str_extract(test, pat2)
# [1] "<="
I've tested this on three separate R installations, one of which is a formally-managed corporate environment. I see the same situation in all three.
Am I misunderstanding how [:punct:] should be used? Or is there possibly a bug?