java - Newline not being replaced in regex match? -


i have following code attempting parse lines starting # , replacing each line empty string, newline not getting stripped:

-- input --

# remove this. # remove # remove line keep # line keep # line 

-- actual output (the . represents blank line) --

.    . . keep # line keep # line 

-- expected output

keep # line keep # line 

-- code --

    string text = "# remove this.\n# remove this\n# remove line\n" +         "keep # line\nkeep # line too";     system.out.println(text);     pattern pattern = pattern.compile("^#(.*)$", pattern.multiline);     matcher m = pattern.matcher(text);     if (m.find()) {         text = m.replaceall("").replaceall("[\n]+$", "");         system.out.println(text);     } 

how can remove \n's in regex match?

use ^#.*[\n] select lines including newline character.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -