[1] "data/133-survey-small.csv" "images/headache.webp"
[3] "images/headwebp.png" "images/penguins.webp"
[5] "images/regex-tester.png" "ps.qmd"
[7] "slides.qmd" "slides.rmarkdown"
Parsing text with regular expressions
[1] "data/133-survey-small.csv" "images/headache.webp"
[3] "images/headwebp.png" "images/penguins.webp"
[5] "images/regex-tester.png" "ps.qmd"
[7] "slides.qmd" "slides.rmarkdown"
Question Write the pattern that matches each of the following:
02:00
[1] "data/133-survey-small.csv" "images/headache.webp"
[3] "images/headwebp.png" "images/penguins.webp"
[5] "images/regex-tester.png" "ps.qmd"
[7] "slides.qmd" "slides.rmarkdown"
[1] "data/133-survey-small.csv" "images/headache.webp"
[3] "images/headwebp.png" "images/penguins.webp"
[5] "images/regex-tester.png" "ps.qmd"
[7] "slides.qmd" "slides.rmarkdown"
[1] "data/133-survey-small.csv" "images/headache.webp"
[3] "images/headwebp.png" "images/penguins.webp"
[5] "images/regex-tester.png" "ps.qmd"
[7] "slides.qmd" "slides.rmarkdown"
You can anchor the regular expression using ^ to match the start or $ to match the end.
You can anchor the regular expression using ^ to match the start or $ to match the end.
# A tibble: 2 × 3
fruit start_a end_a
<chr> <strngr_v> <strngr_v>
1 apple <a>pple apple
2 banana banana banan<a>
[1] "data/133-survey-small.csv" "images/headache.webp"
[3] "images/headwebp.png" "images/penguins.webp"
[5] "images/regex-tester.png" "ps.qmd"
[7] "slides.qmd" "slides.rmarkdown"
[9] "my.webp.pic.png"
[1] │ data/133-survey-small.csv
[2] │ images/headache<.webp>
[3] │ images/hea<dwebp>.png
[4] │ images/penguins<.webp>
[5] │ images/regex-tester.png
[6] │ ps.qmd
[7] │ slides.qmd
[8] │ slides.rmarkdown
[9] │ my<.webp>.pic.png
[1] │ data/133-survey-small.csv
[2] │ images/headache<.webp>
[3] │ images/headwebp.png
[4] │ images/penguins<.webp>
[5] │ images/regex-tester.png
[6] │ ps.qmd
[7] │ slides.qmd
[8] │ slides.rmarkdown
[9] │ my.webp.pic.png
Tip
Regex tester website are very helpful for understanding how your regex is working https://regexr.com/
Question Write the pattern that will match each of the following1:
01:30
Construct your own set: [ABC]
Special characters in a set:
^ at the start negates the set.- expresses a range.Construct your own set: [ABC]
Special characters in a set:
^ at the start negates the set.- expresses a range.Shortcut classes
\d matches any digit;\D matches anything that isn’t a digit.\s matches any whitespace (e.g., space, tab, newline);\S matches anything that isn’t whitespace.\w matches any “word” character, i.e. letters and numbers;\W matches any “non-word” character.Note: These all have to escaped when forming a string to express the pattern.
[1] │ abcd ABCD <12345> -!@#%.
You can change the scope of different operations by grouping characters with ().
You can change the scope of different operations by grouping characters with ().
You can separate different possible patterns with |; reads like “or”.
[3] │ <Stat>istics
[4] │ <Stat>istics
[8] │ <Stat>istics
[9] │ <Stat>istics + Economics
[10] │ <Stat>istics
[11] │ <Stat>istics, Economics, Political Economy
[12] │ <stat>istics
[16] │ <Stat>istics
[18] │ <Stat>istics + Integrative Biology
[21] │ <Stat>istics
[24] │ <Stat>istics
[25] │ <stat>istics
[26] │ <Stat>istics
[31] │ <Stat>istics
[32] │ Data Science & <Stat>s
[34] │ <Stat>istics
[37] │ <Stat>istics
[38] │ <Stat>istics
[42] │ <stat>istic
[43] │ Data Science, <Stat>istics
... and 66 more
Question: Which strings will this match?
Question: Which strings will this match?
How do I extract just the file name from each path?
How do I extract just the file name from each path?
[1] "data/133-survey-small.csv" "images/headache.webp"
[3] "images/headwebp.png" "images/penguins.webp"
[5] "images/regex-tester.png" "ps.qmd"
[7] "slides.qmd" "slides.rmarkdown"
[9] "my.webp.pic.png"
[1] "133-survey-small.csv" "headache.webp" "headwebp.png"
[4] "penguins.webp" "regex-tester.png" "ps.qmd"
[7] "slides.qmd" "slides.rmarkdown" "my.webp.pic.png"
How do you learn and keep track of the str_ functions in stringr?
How do I systemtically keep track of each major a student has?
# A tibble: 202 × 1
major
<chr>
1 Applied mathematics
2 Psychology & Data Science
3 Statistics
4 Statistics
5 math major + ds minor
6 Economics and minor Data Science
7 Political Science
8 Statistics
9 Statistics + Economics
10 Statistics
# ℹ 192 more rows
# A tibble: 202 × 1
major
<chr>
1 Applied mathematics
2 Psychology & Data Science
3 Statistics
4 Statistics
5 math major + ds minor
6 Economics and minor Data Science
7 Political Science
8 Statistics
9 Statistics + Economics
10 Statistics
# ℹ 192 more rows
