假设我有一个包含一些文本的文件.其中有子字符串,如"substr1","substr2","substr3"等.我需要用其他一些文本替换所有这些子串,例如"repl1","repl2","repl3".在Python中,我会创建一个这样的字典:
{
"substr1": "repl1",
"substr2": "repl2",
"substr3": "repl3"
}
Run Code Online (Sandbox Code Playgroud)
并创建用'|'连接键的模式,然后用re.sub函数替换.在Java中有没有类似的简单方法?