【发布时间】:2026-02-21 22:20:03
【问题描述】:
这是场景。
String strText = "ABC abc Abc aBC abC aBc ABc AbC";
// Adding a HTML content to this
String searchText = "abc";
String strFormatted = strText.replaceAll(
"(?i)" + searchText,
"<font color='red'>" + searchText + "</font>");
这会返回一个字符串,其中所有单词都是小写的,当然也是红色的。
我的要求是将strFormatted 作为一个字符串,其大小写与原始字符串相同,但它应该具有字体标签。
这样可以吗?
【问题讨论】:
-
这里,根据您的代码,原始字符串将在
strText,格式化后的字符串将在strFormatted。 -
是的,这不是真正的代码。这个是我编的。无论如何,我希望在用字体标签替换后,在 strFormatted 中保留 strText 的情况..
标签: java regex string replaceall