Expressions régulières intermédiaires en R
Angelo Zehr
Data Journalist
str_match(
"payload: 'Adam, 5, 3', headers: 'Auth...'",
pattern = "[A-Za-z]+, \\d+, \\d+"
)
A donné :
[,1]
[1,] "Adam, 5, 3"
str_match(
"payload: 'Adam, 5, 3', headers: 'Auth...'",
pattern = "([A-Za-z]+), (\\d+), (\\d+)"
)
Donne :
[,1] [,2] [,3] [,4]
[1,] "Adam, 5, 3" "Adam" "5" "3"
str_replace(
"payload: 'Adam, 5, 3', headers: 'Auth...'",
pattern = "([A-Za-z]+), (\\d+), (\\d+)",
replacement = "\\1 tried to log in \\2 times."
)
Renvoie :
"payload: 'Adam tried to log in 5 times.', headers: 'Auth...'"`
str_split(
"a:b:c:d",
pattern = ":",
simplify = FALSE
)
[[1]]
[1] "a" "b" "c" "d"
str_split(
"a:b:c:d",
pattern = ":",
simplify = TRUE
)
[,1] [,2] [,3] [,4]
[1,] "a" "b" "c" "d"
Expressions régulières intermédiaires en R