我正在尝试使用 来检测字符串是否包含特定模式str_detect。我的图案是一系列“....” - 确切的点数未知。我正在尝试使用str_detect如下......
然而,在这种特殊情况下,str_detect返回 TRUE。想知道我在哪里做错了,是否str_detect是正确使用的函数?希望这里有人可以提供帮助吗?
library(stringr)
dot_pat="\\.........................";
str="The primary.objective is of the study."
str_detect(str,dot_pat)
Run Code Online (Sandbox Code Playgroud)
这将返回 TRUE。我期待 FALSE,因为其中的点str不遵循模式。
预先感谢,西马克
您的模式意味着:一个点 (\\.) 后跟 24 个符号。所以这匹配:“.objective is of the Stu”。
如果您想检测(例如 10 个点符号),请使用如下模式:dot_pat="\.{10}"
str_detect("The primary.objective is of the study.", "\\.{10}")
str_detect("hello..........world", "\\.{10}")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17660 次 |
| 最近记录: |