ruby 字符串匹配忽略大小写
我正在尝试创建一个匹配查询,该查询从两个单词之间的字符串中选择文本。我似乎不知道如何使搜索不区分大小写。 例如,考虑文本:
contents = "cat
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec blandit feugiat mi, eu lacinia quam tincidunt eu. Donec eleifend adipiscing neque, in porta dolor vestibulum at. Curabitur id elit vitae nunc feugiat varius. Maecenas euismod euismod mi, eu blandit lectus.
dog"
红宝石代码返回我单词猫和狗之间的拉丁代码是
contents.match(/cat(.*)dog/m)[1].strip
目前,我的“匹配”查询仅在猫和狗是小写时才有效,但我需要照顾猫和狗是否是大写或者第一个字母是大写的。
不太确定将 /i 运算符放在哪里。
I am trying to create a match query which selects text from a string between two words. I can't seem to figure out how to make the search case insensitive.
For example consider the text:
contents = "cat
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec blandit feugiat mi, eu lacinia quam tincidunt eu. Donec eleifend adipiscing neque, in porta dolor vestibulum at. Curabitur id elit vitae nunc feugiat varius. Maecenas euismod euismod mi, eu blandit lectus.
dog"
the ruby code to return me the latin code between the words cat and dog is
contents.match(/cat(.*)dog/m)[1].strip
At the moment my "match" query only works if cat and dog are lowercase but I need to cater for if cat and dog are uppercase or the first letter is upper case.
Not quite sure where to stick the /i operator.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“m”旁边:
Next to the "m":