我正在使用Java中的代码:
String word = "hithere";
String str = "123hithere12345hi";
output(str.replaceAll("(?!"+word+")", "x"));
但是,不是输出:xxxhitherexxxxxxx
就像我想要的那样,而是输出:x1x2x3hxixtxhxexrxex1x2x3x4x5xhxix x
,我尝试了多种不同的正则表达式模式来尝试执行此操作,但是我似乎无法弄清楚如何执行此操作:(
任何帮助都会非常感谢。
好吧,这在技术上是可行的。仅使用替换全部和仅一行,并且假设您的字符串不包含不推荐使用的ASCII字符(BEL)
String string = "hithere";
String string2 = "asdfasdfasdfasdfhithereasasdf";
System.out.println(string2.replaceAll(string,"" + (char)string.length()).replaceAll("[^" + (char)string.length() + "]", "x").replaceAll("" + (char)string.length(), string));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句