嗨,我在替换包含 # 和 @ 字符的确切字符串时遇到了麻烦。我也尝试过mytext.replaceAll('\\b('+text+')\\b',"testtest");
,但也没有帮助。确切的字符串表示确切的单词。
String myStr = "test1 test";
myStr= myStr.replaceAll('\\b('+ Pattern.quote("test") +')\\b',"notest")//out put string "test1 notest"
//Exact word means only "test" is getting replace not "test" from "test1" word to notest1
String myStr1 = "test1 #test";
myStr1 = myStr1.replaceAll('\\b('+Pattern.quote("#test") +')\\b',"notest")//out put string "test1 #test", #test is not replaced
有人可以帮帮我吗。提前致谢