Regex to remove .csv in r -


this going silly.

i have string like:

word <- "dirtyboards.csv"  

i want remove csv part , "dirtyboards".

i trying:

require(stringr) str_extract(word, ".*[^.csv]") 

i in return: "dirtyboard" . "s" before ".csv" goes missing.

i know can ,

gsub(".csv", "", word)

try

library(stringr) str_extract(word, '.*(?=\\.csv)') #[1] "dirtyboards" 

another option works example provided (and not specific)

str_extract(word, '^[^.]+') #[1] "dirtyboards"  

update

including 'foo.csv.csv',

word1 <- c("dirtyboards.csv" , "boardcsv.csv", "foo.csv.csv") str_extract(word1, '.*(?=\\.csv$)') #[1] "dirtyboards" "boardcsv"    "foo.csv"     

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -