3
我想匹配字符串前面不包含「hallo」的字符。如何在R中寫出表達`不包含'的模式?
>string <- c("halloman","hi","dancing","manhallomorning")
>grep("hallo",string,invert=TRUE)
[1] 2 3
grep("(?<!hallo)\\w+",string,perl=TRUE)
[1] 1 2 3 4 #the result is 2 3 which do not contain "hallo" .
如何修改表達不包含hallo
的格局?
我更新了答案。一探究竟。順便說一句,爲什麼你不使用'invert = TRUE'? – falsetru
親愛的falsetru,'invert = TRUE'只能在R中使用,'^((?! hallo)。)* $'可以更廣泛地使用。 –