简体   繁体   English

用grepl全字匹配

[英]Full word match with grepl

I would like to have TRUE FALSE instead of the following. 我想要TRUE FALSE而不是以下内容。 Any suggestion? 有什么建议吗?

testLines <- c("buried","medium-buried")
grepl('\\<buried\\>',testLines)
[1] TRUE TRUE

Perhaps this? 也许这个?

testLines <- c("buried","medium-buried")
grepl('^buried$',testLines)

#[1]  TRUE FALSE

My understanding (and regex is not my forte) is that ^ denotes the start of the string and $ the end. 我的理解(正则表达式不是我的强项)是^表示字符串的开头, $表示字符串的结尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM