I believe the backslash is not considered an escape character by the extended
RE library used by R (perl=FALSE), so it is being treated as a literal. This
means that the last ] is outside the character class and is the atom that the *
applies to.
gsub("^([[:alnum:]\\[\\]]*).*", "\\1", "a]]]rra
I just found a curious behaviour of regexp and I'd like to share with y'all.
gsub("^([[:alnum:]\\[\\]]*).*", "\\1", "array[n] <- 10", perl=T) #
works as expected ("array[n]")
gsub("^([[:alnum:]\\[\\]]*).*", "\\1", "array[n] <- 10", perl=F) #
doesn't work ("a")
I didn't find anything in the docum
2 matches
Mail list logo