Expressions régulières intermédiaires en R
Angelo Zehr
Data Journalist
| Classe de caractères | Exemple |
|---|---|
\\d ou [:digit:] |
0, 1, 2, 3,… |
\\w ou [:word:] |
a, b, c…, 1, 2, 3…, _ |
[A-Za-z] ou [:alpha:] |
A, B, C,…, a, b, c,… |
[aeiou] |
soit a, e, i, o ou u |
\\s ou [:space:] |
" ", tabulations ou sauts de 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} |
au moins 2 fois, au plus 3 fois |
\\w{2,} |
au moins 2 fois, sans maximum |
\\w+ |
1 fois ou plus |
\\w* |
0, 1 ou plusieurs fois |
| Original | Négation |
|---|---|
\\d correspond aux chiffres |
\\D correspond à tout sauf les chiffres |
\\w correspond aux caractères de mot |
\\W correspond à tout sauf les caractères de mot |
\\s correspond aux espaces |
\\S correspond à tout sauf les 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