Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果 'A*B*C*D*' 是正则表达式,并且
string <- c("AB"),
有没有办法检查字符串是否被正则表达式接受?答案是肯定或否定。
听起来您正在寻找grep:
grep
> length(grep("^A*B*C*D*$", string)) > 0 [1] TRUE > length(grep("^A*B*C*D$", string)) > 0 [1] FALSE
我添加了^and$以确保只能匹配整个字符串。如果您不想这样做,只需删除它们即可。
^
$