For a begineer in R or any language,regular expression might seem like a daunting task . Rebus package in R gives a lowers the barrier for common regular expression tasks and is useful for a begineer or even for advanced users for most of the common regex skills in a more intuitive yet verbose way .Check out the package and try this exercises to test your knowledge .
Load stringr/stringi as well for this set of exercise . I encourage you to do this and
this before working on this set .
Answers are available here.
If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.
create two strings
Suppose you have a vectore
x <- c("stringer","stringi","rebus","redbus")
use rebus and find the strings starting with st .Hint use START from rebus
Use the same string vectore and find the strings which ends with bus.
you have a vector like
m <- c("aba","aca","abba","accdda")
find the strings which starts and ends with a and have a single character in between
Hint – use ANY_CHAR
y <- c("brain","brawn","rain","train")
find all the strings that starts with br and ends with n .
Hint – use any_char with hi=Inf to build the regex
Use the same vector as previous exercise and find strings starting with br or tr .
Hint – or
Now we turn our attention to character class,if you are familiar with character classes in regex , you will find it pretty easy with rebus and if you are starting with regex .you might find it easy to remember with rebus
Suppose you have a vector
l <- c("Canada","america","france")
Find string with C or m in it .so your answer should be Canada and America
From the string 123abc ,find the digits ,using rebus .
Create a character class for vowels and find all the Vowels in the vector
vow <- c("blue","sue","CLUE","TRUE")
Find the characters other than vowels from above vector .
Now create a new vector
vow1 <- c("blue","sue","CLUE","TRUE","aue")
find the string which is made of only vowels