Grepl在R期间? [英] Grepl for period in R?

查看:237
本文介绍了Grepl在R期间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说我有一个字符串你好。我想看看这个字符串是否包含句点:

  text<  - Hello。 
results< - grepl(。,text)

结果为TRUE ,但如果文本是你好,它也会返回。我非常困惑,在文档中我找不到任何关于这个的内容,它只在这段时间内做到这一点。



有什么想法?



谢谢!

解决方案


 > grepl(\\。,Hello。)
[1] TRUE
> grepl(\\。,Hello)
[1] FALSE

表示SimonO101指出的任何内容,如果您想查找明确的,那么您必须使用 \\。来表示查找



R文档在正则表达式上很广泛,您还可以查看此链接以了解点的用法。


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆