簡體   English   中英

R中具有模式組合的正則表達式

[英]Regular Expression with pattern combination in R

盡管我已經參考了多個線程,但是我無法使我的代碼正常工作,也許有人可以在這里找到解決方案。

我想在目錄中查找文件,該目錄以

start.contain <- "VP01_SPSG2015_Experimental"   ## beginning of the file name

並以

stop.contain <- ".vmrk"  ## the file extension

我必須喂什么模式

findfile <- list.files(path, pattern = ???)

查找我的文件?

您可以使用

start.contain <- "VP01_SPSG2015_Experimental"   ## beginning of the file name
stop.contain <- "[.]vmrk"  ## the file extension
findfile <- list.files(path, pattern = paste0("^", start.contain, ".*", stop.contain, "$"))

^表示在字符串開頭匹配$表示在字符串結尾匹配 .*將匹配任何零個或多個字符。

請注意,在正則表達式中, . 必須轉義或在字符類( [.] )中使用,才能將其視為文字。 因此,您應該使用"[.]vmrk""\\\\.vmrk"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM