我有绳子
String test = "
test_one {
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
}
test_two {
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
}
test_three {
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
}
"我需要将'test_two‘或'test_three’中括号中的整个文本替换为另一个文本ex“这是我的文本”;
预期产出:
String test = "
test_one {
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
}
test_two {
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
}
test_three {
**This is my text**
}
"发布于 2022-07-08 09:03:51
我们可以用启用了点所有模式的regex替换:
String test = "test_one {\nLorem Ipsum is simply dummy text of the printing and typesetting industry.\n}\ntest_two {\nLorem Ipsum is simply dummy text of the printing and typesetting industry.\n}\n\ntest_three {\nLorem Ipsum is simply dummy text of the printing and typesetting industry.\n}";
test = test.replaceAll("(?s)\\btest_three \\{.*?\\}", "test_three {\nThis is my text\n}");
System.out.println(test);这些指纹:
test_one {
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
}
test_two {
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
}
test_three {
This is my text
}https://stackoverflow.com/questions/72908935
复制相似问题