我有一个长字符串,想要用匹配正则表达式(组)的部分替换所有匹配项。
例如:
String = "This is a great day, is it not? If there is something, THIS IS it. <b>is</b>".
我想将所有的单词 "is"
替换为, 例如, "<h1>is</h1>"
。大小写应该与原始字符串保持一致。所以我想要的最终字符串是:
This <h1>is</h1> a great day, <h1>is</h1> it not? If there <h1>is</h1> something,
THIS <h1>IS</h1> it. <b><h1>is</h1></b>.
我尝试的正则表达式:
Pattern pattern = Pattern.compile("[.>, ](is)[.<, ]", Pattern.CASE_INSENSITIVE);