Ok I'm giving up and ask the question after I read through the help article of regex and still don't have a clue what I'm looking for:
I Have a list of files:
files <- c("files_combined.csv","file_1-10.csv","file_11-20.csv",
"file_21-30.csv","file_2731-2740.csv","file_2731-2740.txt")
I want only the csv files that start with "file_"
and end with ".csv"
. I know the it looks something like this:
grep(pattern = "^file_???.csv$" ,files)
But I need to find the correct regular expression that ignores the number of characters between the first and the second pattern ("file_"
+ ".csv"
). I'd really appreciate if somebody knows a complete list with the regular expressions in R since it is tedious to read through the help every time and, as in my case not successful, sometimes...
R offers a function for doing wildcard expansion using glob patterns for those who don't like regex:
files <- Sys.glob("file_*.csv")
This should match your pattern.
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