[英]Regexp for Visual Studio (2013+) to match and replace the exact same string
[英]replace exact string match with regexp in R
我有一個需要清洗的字符串向量。 我已經能夠自己清理很多東西,但是我遇到一件事。
有些字符串的鏈為“ @ 56;”。 開頭(數字有所不同)。 因此,字符串可以是“ @ 56;褲子”或“ @ 897;褲子”,我想像“褲子”一樣保留它。
我寫了以下代碼:
gsub("[@[:digit:];]", "", 'mystring')
但在以下情況下失敗:
gsub("[@[:digit:];]", "", '@34skirt') # returns 'skirt'
我想在這種情況下返回'@ 34skirt',因為 從最后開始消失了。
我要完全匹配。 有關如何執行此操作的任何想法? 我試着添加\\,但是它不起作用
我們可以試試
sub("@\\d+;", "", v1)
#[1] "mystring" "@34skirt" "trousers" "trousers"
v1 <- c('mystring', '@34skirt', '@56;trousers', '@897;trousers')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.