Matching the start or end of the string
rebus provides START and END shortcuts to specify regular expressions that match the start and end of the string. These are also known as anchors. You can try it out just by typing
START
You'll see the output <regex> ^. The <regex> denotes this is a special regex object and it has the value ^. ^ is the character used in the regular expression language to denote the start of a string.
The special operator provided by rebus, %R% allows you to compose complicated regular expressions from simple pieces. When you are reading rebus code, think of %R% as "then". For example, you could combine START with c,
START %R% "c"
to match the pattern "the start of string then a c", or in other words: strings that start with c. In rebus, if you want to match a specific character, or a specific sequence of characters, you simply specify them as a string, e.g. surround them with ".
이 연습은 강의의 일부입니다
String Manipulation with stringr in R
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Some strings to practice with
x <- c("cat", "coat", "scotland", "tic toc")
# Print END
# Run me
str_view(x, pattern = START %R% "c")