this is going to be silly.
I have a string like:
word <- "dirtyboards.csv"
I want to remove the csv part and get "dirtyboards".
I am trying:
require(stringr)
str_extract(word, ".*[^.csv]")
I get in return: "dirtyboard" . The "s" before the ".csv" goes missing.
I know I can do ,
gsub(".csv", "", word)
Try
library(stringr)
str_extract(word, '.*(?=\\.csv)')
#[1] "dirtyboards"
Another option which works for the example provided (and not very specific)
str_extract(word, '^[^.]+')
#[1] "dirtyboards"
Including 'foo.csv.csv',
word1 <- c("dirtyboards.csv" , "boardcsv.csv", "foo.csv.csv")
str_extract(word1, '.*(?=\\.csv$)')
#[1] "dirtyboards" "boardcsv" "foo.csv"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With