正则表达式在文本中查找整个单词但不区分大小写 [英] Regex to find whole word in text but case insensitive
本文介绍了正则表达式在文本中查找整个单词但不区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下文字:
我喜欢在我的碎馅饼里加一点朗姆酒.
I like a bit of rum with my crumble pie.
我想构建一个正则表达式搜索表达式,只返回朗姆酒"而不是崩溃"这个词.另外我需要它不区分大小写.
I want to build a regex search expression to return just the word 'rum' not 'crumble' as well. Also I need it to be case insensitive.
推荐答案
Use word boundary \b
in your regex,
Use word boundary \b
in your regex,
(?i)\brum\b
或
使用前瞻和后视,
(?i)(?<= |^)rum(?= |$)
这篇关于正则表达式在文本中查找整个单词但不区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文