0
stringr正則表達式我有以下代碼:的第一個完整的* .zip文件的文件名
test_zip_col <- "daily_44201_2015.zip259,151 Rows2,958 KBAs of 2015-11-27"
test_zip_col2 <- str_extract(test_zip_col, '^*\\.zip$')
test_zip_col
test_zip_col2
我要提取的文件名*.zip
的第一次出現。在這個例子中,我希望提取:
"daily_44201_2015.zip"
任何人都可以請解釋如何修改我的str_extract
代碼,因此它不會產生NA
價值?
有了'stringi'這將是'stringi :: stri_extract_first' –
喜(test_zip_col,正則表達式= 「* \\拉鍊。」) - 謝謝。根據你的建議我修改並使用了'stringr :: str_extract(string = test_zip_col,pattern =「。* \\。zip」)'並且它工作正常。如果您將此作爲答案提交,我可以接受,因爲這是最簡單的解決方案 – user4687531
如果一個字符串中包含多個zip文件,則不會爲您提供第一個zip文件。它與stringi一起工作,因爲有一個特殊的函數來提取第一個匹配,但不是在stringr中。 –