grepl 一段“."在R? [英] grepl for a period "." in R?
问题描述
假设我有一个字符串Hello".我想看看这个字符串是否包含句点:
Lets say I have a string "Hello." I want to see if this string contains a period:
text <- "Hello."
results <- grepl(".", text)
这将返回结果为 TRUE,但如果文本是 "Hello"
没有句点,它也会返回结果.
This returns results as TRUE, but it would return that as well if text is "Hello"
without the period.
我很困惑,我在文档中找不到任何关于此的信息,而且它仅在此期间执行此操作.
I'm confused, I can't find anything about this in the documentation and it only does this for the period.
有什么想法吗?
推荐答案
查看与这些示例的不同之处
See the differences with these examples
> grepl("\\.", "Hello.")
[1] TRUE
> grepl("\\.", "Hello")
[1] FALSE
.
表示 SimonO101 指出的任何内容,如果您想查找显式的 .
那么您必须使用 \\ 跳过它.
表示寻找 .
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 文档在正则表达式方面非常广泛,您也可以查看此链接以了解其用法点.
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屋!