I was told that [[a-z][0-9]]
is equivalent to [a-z0-9]
, but I tried a few examples:
grepl("[[a-z][0-9]]", "d")
returns FALSE
.
Similarly, grepl("[[:alpha:][0-9]]", "d")
returns FALSE
while things like grepl("[[:upper:][:lower:]]", "d")
works fine.
May I ask if this indicates that double square brackets could only be used for combining things of the form "[:...:]"
but not for things like [A-z]
or [0-9]
?
If so, why would R stop us from doing so? And what do grepl("[[a-z][0-9]]", "d")
and grepl("[[a-z]]", "d")
actually mean?
Forthermore, I know that we need to use double square brackets, say, for things like "[[:digit:]]"
, because "[:digit:]"
would rather search for ":", "d", "i", "g" or "t" (from this question). But how exactly is the structure of "[[:digit:]]"
being interpreted? (just a guess: does R interpret it as the trivial union of [:digit:]
with itself so that it's just a 'readable' [:digit:]
for R?)