1.
test1
# [1] "abcd""abc1""ab2b""a3cd""4bcd"
test1[grep('[^abc1-3]', test1)]
# [1] "abcd""a3cd""4bcd"
test1[grep('[^a-d1-3]', test1)]
# [1] "4bcd"
test1[grep('[^4]', test1)]
# [1] "abcd""abc1""ab2b""a3cd""4bcd"
2.
test5 <- c('lo', 'lol', 'lolo', 'olo', 'lool')
test5[grep('loll*', test5)]
# [1] "lol""lolo"
3.
test5
# [1] "lo""lol""lolo""olo""lool"
test5[grep('lolo+', test5)]
# [1] "lolo"
test5[grep('lol+', test5)]
# [1] "lol""lolo"
I'm studying basic contents about regular expression using R. But I can't understand why above three examples return those results.
For example, when using ^ in [], I learned that it returns the characters which don't involve the letters behind ^. But results don't seem like that.
I'm not good at English so I have difficulty in explaining all kinds of thing that I can't understand but I'll really appreciate if anyone can teach me why those results are returned by those R codes.
:(