Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.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 agrepl不适用于正则表达式_Regex_R - Fatal编程技术网

Regex agrepl不适用于正则表达式

Regex agrepl不适用于正则表达式,regex,r,Regex,R,我需要使用正则表达式获取字符串中的部分匹配。我可以得到准确的答案: pattern <- "(^| )shower only($| )" stringInQuestion<-"Delta Vero 1-Handle Shower Only Faucet Trim Kit in Chrome" grepl(pattern,stringInQuestion, ignore.case=TRUE,perl=TRUE) [1] TRUE agrepl(pattern,stringInQ

我需要使用正则表达式获取字符串中的部分匹配。我可以得到准确的答案:

pattern <- "(^| )shower only($| )"

stringInQuestion<-"Delta Vero 1-Handle Shower Only Faucet Trim Kit in Chrome"

grepl(pattern,stringInQuestion, ignore.case=TRUE,perl=TRUE)

[1] TRUE

agrepl(pattern,stringInQuestion, ignore.case=TRUE,fixed = FALSE, max.distance=0.2)

[1] FALSE

有人能帮我弄清楚到底发生了什么吗?

既然你只想检查整个单词的存在,我建议将模式减少到

pattern <- "\\bshower only\\b"

请注意,
max.distance
应根据您的实际输入进行测试,并相应地进行测试。

研究
max.distance
参数。如果将其设置为例如10,则有效。将模式更改为。您只需检查整个单词
shower only
,因此使用单词边界
0.2
将允许匹配带有错误的短语,比如说
Showerrrrr Only
,但不会匹配
Showerrrrrr Only
谢谢!成功了,我支持这个。我试着让这件事起作用:``>grepl(\\\s+),“abc abc 123\t.!\(){}[]”[1]TRUE>agrepl(\\\s+),“abc abc 123\t.!?\(){}[]”[1]FALSE>agrepl(\\\s+),“abc abc abc 123\t.!?\(){[]”,max.distance=1)[FALSE``在最后两种情况下应该是
TRUE
。仅当我添加
fixed=FALSE
时,它才起作用,但默认情况下应该是这样。在这里编辑不允许我转到新行或添加空行,即使我尝试“复制并粘贴”。我想我现在的问题是“我如何与开发人员联系”。或者我可以自己修吗?
pattern <- "\\bshower only\\b"
pattern <- "\\bshower only\\b"
stringInQuestion<-"Delta Vero 1-Handle Shower Only Faucet Trim Kit in Chrome"
grepl(pattern,stringInQuestion, ignore.case=TRUE,perl=TRUE)
agrepl(pattern,stringInQuestion, ignore.case=TRUE,fixed = FALSE, max.distance=0.2)
## [1] TRUE
## [1] TRUE