99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
2018-11-19 閱讀量: 966
關(guān)于正則表達式的練習(xí)示例(二)

6.從一行文本中刪除標(biāo)點符號

going <- "a1~!@#$%^&*bcd(){}_+:efg\"<>?,./;'[]-="
gsub(pattern = "[[:punct:]]+",replacement = "",x = going)

7.從包含字母數(shù)字字符的字符串中刪除數(shù)字

c2 <- "day of 2nd ID5 Conference 19 12 2005"
從上面的字符串中,所需的輸出是“第二次ID5會議日”。 您不能使用簡單的“[[:digit:]] +”正則表達式,因為它將匹配給定字符串中的所有可用數(shù)字。 相反,在這種情況下,我們將檢測數(shù)字邊界以獲得所需的結(jié)果。

gsub(pattern = "\\b\\d+\\b",replacement = "",x = c2)

8.在字符串中查找數(shù)字的位置

string <- "there were 2 players each in 8 teams"
gregexpr(pattern = '\\d',text = string) #or
unlist(gregexpr(pattern = '\\d',text = "there were 2 players each in 8 teams"))

9.在字符串中提取括號內(nèi)的可用信息(括號)

string <- "What are we doing tomorrow ? (laugh) Play soccer (groans) (cries)"
gsub("[\\(\\)]","",regmatches(string, gregexpr("\\(.*?\\)", string))[[1]])

說明:在此解決方案中,我們使用了惰性匹配技術(shù)。 首先,使用regmatches,我們用諸如(cries)(呻吟)之類的詞來提取括號(笑)。 然后,我們只需使用gsub()函數(shù)刪除括號。

10.僅提取范圍中的第一個數(shù)字

x <- c("75 to 79", "80 to 84", "85 to 89")
gsub(" .*\\d+", "", x)

11.從給定字符串中提取電子郵件地址

string <- c("My email address is abc@boeing.com","my email address is def@jobs.com","aescher koeif","paul renne")
unlist(regmatches(x = string, gregexpr(pattern = "[[:alnum:]]+\\@[[:alpha:]]+\\.com",text = string)))

0.0000
2
關(guān)注作者
收藏
評論(0)

發(fā)表評論

暫無數(shù)據(jù)
推薦帖子