Grepl在R期间? [英] Grepl for period in R?
问题描述
可以说我有一个字符串你好。我想看看这个字符串是否包含句点:
text< - Hello。
results< - grepl(。,text)
结果为TRUE ,但如果文本是你好,它也会返回。我非常困惑,在文档中我找不到任何关于这个的内容,它只在这段时间内做到这一点。
有什么想法?
谢谢!
> grepl(\\。,Hello。)
[1] TRUE
> grepl(\\。,Hello)
[1] FALSE
。
表示SimonO101指出的任何内容,如果您想查找明确的。
,那么您必须使用 \\。
来表示查找。
Lets say I have a string "Hello." I want to see if this string contains a period:
text <- "Hello."
results <- grepl(".",text)
This returns results as TRUE, but it would return that as well if text is "Hello". I'm extremely confused, I can't find anything about this in the documentation and it only does this for the period.
Any ideas?
Thanks!
See the differences with these examples
> grepl("\\.", "Hello.")
[1] TRUE
> grepl("\\.", "Hello")
[1] FALSE
the .
means anything as pointed out by SimonO101, if you want to look for an explicit .
then you have to skip it by using \\.
which means look for a .
R documentation is extensive on regular expressions, you can also take a look at this link to understand the use of the dot.
这篇关于Grepl在R期间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!