1
我試圖創建在R.我想在這裏如圖所示的模式正則表達式的模式,[R正則表達式匹配,直到最後一個點
file1 <- "example.txt"
file2 <- "example.ffe.2f2.csv"
files <- c(file1,file2)
#pattern that matches everything up to, but not including last .
pattern <- ".*(?=\.)"
m <- regexpr(pattern, files)
但是我上的圖案線得到一個錯誤說
Error: '\.' is an unrecognized escape in character string starting "".*(?=\."
我想正則表達式匹配的file1
example
和example.ffe.2f2
在file2
。任何建議/我做錯的事情?它在regex101.com上正常工作,所以我知道該模式是正確的。
\\不是一個斜槓我認爲 –
「\」是R.中的轉義字符,您需要使用「\\」作爲文字反斜槓。 –
也使用'regexpr(pattern,files,perl = TRUE)',因爲您使用的是超越基本的分組類型。 –