Gevorderde reguliere expressies in R
Angelo Zehr
Data Journalist
| Tekenklasse | Voorbeeld |
|---|---|
\\d of [:digit:] |
0, 1, 2, 3,… |
\\w of [:word:] |
a, b, c…, 1, 2, 3…, _ |
[A-Za-z] of [:alpha:] |
A, B, C,…, a, b, c,… |
[aeiou] |
a, e, i, o of u |
\\s of [:space:] |
" ", tabs of regeleinden |
str_match_all() |
Resultaat |
|---|---|
"Hi John_35", "\\d" |
"3", "5" |
"Hi John_35", "\\w" |
"H", "i", "J", "o", "h", "n", "_", "3", "5" |
"Hi John_35", "[A-Za-z]" |
"H", "i", "J", "o", "h", "n" |
"Hi John_35", "[aeiou]" |
"i", "o" |
"Hi John_35", "\\s" |
" " |
| Syntax | Betekenis |
|---|---|
\\w{2} |
precies 2 keer |
\\w{2,3} |
minimaal 2 keer, maximaal 3 keer |
\\w{2,} |
minimaal 2 keer, geen maximum |
\\w+ |
1 of meer herhalingen |
\\w* |
0, 1 of meer herhalingen |
| Origineel | Negatie |
|---|---|
\\d matcht cijfers |
\\D matcht alles behalve cijfers |
\\w matcht woordtekens |
\\W matcht alles behalve woordtekens |
\\s matcht spaties |
\\S matcht alles behalve spaties |
[a-zA-Z] matcht letters |
[^a-zA-Z] matcht alles behalve letters |
str_match_all("Toy Story 3", "[\\d\\s]")
Resultaat:
[,1]
[1,] " "
[2,] " "
[3,] "3"
Gevorderde reguliere expressies in R