Possible Duplicate:
regex replace all ignore case
如何获得所需的输出?
输入字符串-
"Software Industry. software Industry. SOFTWARE INDUSTRY. software industry. "
要搜索的词 -
"software industry"
输出 -
"*Software Industry*. *software Industry*. *SOFTWARE INDUSTRY*. *software industry*. "
简而言之,我必须找到一个短语并用星号(*)开头和结尾替换相同的短语,忽略大小写..
最佳答案
您可以将 replaceAll
与 (?i)
一起使用,这将进行不区分大小写
替换。
String str = "Software Industry. software Industry. SOFTWARE INDUSTRY. "+
"software industry. "
str = str.replaceAll("(?i)(software industry)", "\\*$1\\*");
关于java - 正则表达式 - 搜索一个单词并使用不区分大小写的相同单词替换它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12928265/