Expressions régulières intermédiaires en R
Angelo Zehr
Data Journalist
| Classe de caractères | Exemple |
|---|---|
\\d or [:digit:] |
0, 1, 2, 3,… |
\\w or [:word:] |
a, b, c…, 1, 2, 3…, _ |
[A-Za-z] or [:alpha:] |
A, B, C,…, a, b, c,… |
[aeiou] |
soit a, e, i, o ou u |
\\s or [:space:] |
" ", tabulations ou retours à la ligne |
str_match_all() |
Résultat |
|---|---|
"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" |
" " |
| Syntaxe | Signification |
|---|---|
\\w{2} |
exactement 2 fois |
\\w{2,3} |
minimum 2 fois, maximum 3 fois |
\\w{2,} |
minimum 2 fois, sans maximum |
\\w+ |
1 ou plus répétitions |
\\w* |
0, 1 ou plus répétitions |
| Original | Négation |
|---|---|
\\d correspond aux chiffres |
\\D correspond à tout sauf aux chiffres |
\\w correspond aux caractères de mot |
\\W correspond à tout sauf aux caractères de mot |
\\s correspond aux espaces |
\\S correspond à tout sauf aux espaces |
[a-zA-Z] correspond à l'alphabet |
[^a-zA-Z] correspond à tout sauf à l'alphabet |
str_match_all("Toy Story 3", "[\\d\\s]")
Résultat :
[,1]
[1,] " "
[2,] " "
[3,] "3"
Expressions régulières intermédiaires en R