I am experiencing some difficulties with Regular expression in R.
I am looking for all files that match the following pattern:
the files name should start with "11" and ends with ".JPG"
What regular expression should I use?
list.files(path='my_path', pattern=???)
Thank you
You can use ^
to indicate "at the start", $
to indicate "at the end", and .*
for all the stuff in between, so you can try something like:
list.files(path='my_path', pattern="^11.*\\.JPG$")
Try this little experiment out and see how the results of each pattern differs:
someFiles <- c("testpost.html", "mytest.html", "testing.html", "testing.txt")
grep("test", someFiles)
grep("^test", someFiles)
grep("\\.txt", someFiles)
grep("^test.*\\.html", someFiles)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.