“'\w' is an unrecognized escape” in grep

雨燕双飞 提交于 2020-01-21 03:02:41

问题


I'm using grep in some projects in R (which uses a perl=TRUE flag) and for the life of me I can't figure out why R keeps throwing errors. My query is as follows:

d$SomeColumn[grep("(?ix)<VNW[^;]*;(dis|dat)> \w*<N\(", d$Right, perl=TRUE)] <- 1

However, R throws the following error:

Error: '\w' is an unrecognized escape in character string starting ""<VNW[^;]*;(dis|dat)> \w"

回答1:


You need to escape the backslashes one more time in r.

d$SomeColumn[grep("(?ix)<VNW[^;]*;(dis|dat)> \\w*<N\\(", d$Right, perl=TRUE)] <- 1

                                              |     |


来源:https://stackoverflow.com/questions/27528581/w-is-an-unrecognized-escape-in-grep

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!