我有以下文件内容,我正在尝试在每行的开头为字符的连续块(特别是'>')匹配一个正则表达式,并删除该匹配文本块:
-- file.txt (Before regx match and replace) --
keep this
> remove this
>
> remove this too
-- EOF --
-- file.txt (After regex mach and replace) --
keep this
-- EOF --
我正在尝试将其与多行匹配(即删除以“>”开头的任何行)。这是正确的还是最好的方法?以下似乎不起作用。
// String text = <file contents from above...the Before contents>
Pattern PATTERN =
Pattern.compile("^>(.*)$", Pattern.MULTILINE);
Matcher m = PATTERN.matcher(text);
if (m.find()) {
// Matches each line starting with > and deletes (replaces with "") the line
text = m.replaceAll("");
}