Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 用正则表达式检测R中数据帧中的字边界_Regex_R_Dataframe_Word Boundary - Fatal编程技术网

Regex 用正则表达式检测R中数据帧中的字边界

Regex 用正则表达式检测R中数据帧中的字边界,regex,r,dataframe,word-boundary,Regex,R,Dataframe,Word Boundary,我有一个名为all的data.frame,它有一列因子,这些因子包括“word”,“nonword”和其他一些因子。我的目标是只选择具有因子值“word”的行 我的解决方案grep(“\bword\b”,all[,5])不返回任何内容 为什么无法识别单词边界?在R中,您需要两次\: grep("\\bword\\b", all[5]) 替代解决方案: grep("^word$", all[5]) which(all[5] == "word") 两种解决方案都有效,谢谢。您知道为什么“\b单

我有一个名为
all
的data.frame,它有一列因子,这些因子包括
“word”
“nonword”
和其他一些因子。我的目标是只选择具有因子值“word”的行

我的解决方案
grep(“\bword\b”,all[,5])
不返回任何内容


为什么无法识别单词边界?

在R中,您需要两次
\

grep("\\bword\\b", all[5])
替代解决方案:

grep("^word$", all[5])

which(all[5] == "word")

两种解决方案都有效,谢谢。您知道为什么“\b单词\b”在这种情况下不起作用吗?+1模式
grep(“^word$”,…)
将匹配整个字符串,而不仅仅是单词。。即使在这里它们也没什么区别。为什么不干脆
all%>%filter(word中的列%)