【发布时间】:2020-04-22 07:24:12
【问题描述】:
我阅读了关于 regex 的内容并跨越了单词边界。我找到了一个question,它是关于\b 和\B 之间的区别。使用此问题中的代码不会给出预期的输出。这里:
grep("\\bcat\\b", "The cat scattered his food all over the room.", value= TRUE)
# I expect "cat" but it returns the whole string.
grep("\\B-\\B", "Please enter the nine-digit id as it appears on your color - coded pass-key.", value= TRUE)
# I expect "-" but it returns the whole string.
我使用问题中描述的代码,但建议使用两个反斜杠here。使用一个反斜杠也不起作用。我做错了什么?
【问题讨论】: