string = "2001 - l'odyssée de l'espace"
What the regex to extract only "l'odyssée de l'espace" with str_exctract()?
str_extract_all(string, '[^-[:digit:]]') would work, but a can't concat it back together.
string = "2001 - l'odyssée de l'espace"
What the regex to extract only "l'odyssée de l'espace" with str_exctract()?
str_extract_all(string, '[^-[:digit:]]') would work, but a can't concat it back together.
Here's a base R approach:
trimws(gsub("[-[:digit:]]", "", string))
# [1] "l'odyssée de l'espace"
An imperfect stringr extraction:
stringr::str_extract_all(string, "[^-[:digit:]]+")
# [[1]]
# [1] " " " l'odyssée de l'espace"
which can be extended with
grep("\\S", stringr::str_extract_all(string, "[^-[:digit:]]+", simplify = TRUE), value = TRUE)
# [1] " l'odyssée de l'espace"
Another way, to extract what is needed :
sub('\\d+\\s*-\\s*(.*)', '\\1', string)
#[1] "l'odyssée de l'espace"