我有很多代码,想找到并替换其中的一些文本。我想替换所有匹配项,但不包括注释中的匹配项。假设我想在代码中查找并替换字符串"text“。replaced
// some text /* does not need to be replaced because this string begins from "/
我想替换java字符串中的一些文本,但如果文本位于由$ and &定义的部分中,则不想替换它。示例:替换文本foo的字符串"$foo& bar foo“将是"$foo& bar $foo&”。因此,替换文本必须使用$ and &但如果已经应用了转义,则必须转义。目前,我正在使用正则表达式([^\\$]|^)text([^&