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)一起使用,这将替换case-insensitive

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/

10-10 13:43