Hi,

So I just took an intro to R programming class and one of the lectures was on 
Regular Expressions. I've been playing around with various R functions that use 
Regular Expressions.
But this has me stumped. This was part of a quiz and I got it right through 
understanding the syntax. But when I try to run the thing it returns 
'integer(0)'. Can you please tell me what I am doing wrong?

#I copied and pasted this:
going up and up and up
night night at 8
bye bye from up high
heading, heading by 9

#THEN
lines<-readLines("clipboard")
#This is what it looks like in R
lines
[1] "going up and up and up"
[2] "night night at 8"
[3] "bye bye from up high"
[4] "heading, heading by 9"

#THIS IS WHAT IS NOT WORKING THE WAY I THOUGHT. I was expecting it to return 2.
# "night night at 8" follows the pattern: Begins with a word then has at least 
one space then the same word then has at least one space then a word then a 
space then a single digit number.
grep("^([a-z]+) +\1 +[a-z]+ [0-9]",lines)
integer(0)

#But simple examples DO work
grep("[Hh]",lines)
[1] 2 3 4
grep('[0-9]',lines)
[1] 2 4

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to