【发布时间】:2014-01-23 07:56:08
【问题描述】:
我有一个很长的文本,我正在尝试扫描它以便在其中找到几个单词。 我正在寻找一个可以解决问题但忽略大小写敏感性的函数。
非常重要:我无法将字符串更改为小写或大写!这是一个帖子应用,如果我要更改它,回滚会很棘手。
例子:
str = "According to a new report from TechCrunch, Apple has acquired the photo technology startup SnappyLabs. The company is a one-man development team known for creating the SnappyCam app."
word = "the"
str.scan(/word/) # need to find "the" and "The"
更新
如何获取单词第一次出现的字符串索引?
如果其他人需要它,请使用str =~ (/word/i)(感谢@steenslag)
【问题讨论】:
标签: ruby regex string substring