我有一个包含多行的输入字符串(由 \n 分隔)。我需要在这些行中搜索一个模式,如果找到,则用空字符串替换整行。
我的代码如下:
我期待的回应是:
我无法理解它,请帮帮我。
谢谢, Amit
我的代码如下:
Pattern p = Pattern.compile("^.*@@.*$");
String regex = "This is the first line \n" +
"And this is second line\n" +
"Thus is @@{xyz} should not appear \n" +
"This is 3rd line and should come\n" +
"This will not appear @@{abc}\n" +
"But this will appear\n";
Matcher m = p.matcher(regex);
System.out.println("Output: "+m.group());
我期待的回应是:
Output: This is the first line
And this is second line
This is 3rd line and should come
But this will appear.
我无法理解它,请帮帮我。
谢谢, Amit
replaceAll(...)
示例中,我展示了如何做到这一点。 - Bart Kiers