我正在处理包含图像标记和新行标记的文本段落.目标是通过将所有单词charachter的颜色更改为白色来使所有非单词charechter显示清楚.我正在使用java作为编程语言.我想使用正则表达式,但问题是它改变了图像标签内的单词charechters.
String RegEx = "\\w|[àÀâÂäÄáÁéÉèÈêÊëËìÌîÎïÏòÒôÔöÖùÙûÛüÜçÇ’ñ]";
try {
Pattern mypattern = Pattern.compile(RegEx, Pattern.CASE_INSENSITIVE);
Matcher myMatcher = mypattern.matcher(sentence);
int offset = 0;
while (myMatcher.find()) {
int start = myMatcher.start() + offset;
int end = myMatcher.end() + offset;
sentence = sentence.substring(0, start) + "<font color=\"white\">" + sentence.substring(start, end) + "</font>" + sentence.substring(end, sentence.length());
offset += 28;
}
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
所需结果的例子.输入:
Most implementations<img title="hello:" alt="hello:{}" src="http://images.doctissimo.fr/hello.gif" class="wysiwyg_smiley" /> provide ASDF as a module, and you can …