![](/img/trans.png)
[英]R - Regular Expression - Match the following pattern: WhitespaceHyphenWhitespaceSingledigit
[英]Regular expression to find files that match a pattern in R
我在R中使用正則表達式遇到了一些困難
我正在尋找符合以下模式的所有文件:
文件名應以“11”開頭,以“.JPG”結尾
我應該使用什么正則表達式?
list.files(path='my_path', pattern=???)
謝謝
您可以使用^
來表示“在開始時”, $
表示“在結尾”,而.*
表示中間的所有內容,因此您可以嘗試以下方法:
list.files(path='my_path', pattern="^11.*\\.JPG$")
嘗試這個小實驗,看看每個模式的結果如何不同:
someFiles <- c("testpost.html", "mytest.html", "testing.html", "testing.txt")
grep("test", someFiles)
grep("^test", someFiles)
grep("\\.txt", someFiles)
grep("^test.*\\.html", someFiles)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.