Reputation: 18239
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
Upvotes: 0
Views: 227
Reputation: 193687
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)
Upvotes: 2