Here you can find the source of replaceAllPerLine(Pattern pattern, String value, String replacement)
static String replaceAllPerLine(Pattern pattern, String value, String replacement)
//package com.java2s; import java.util.Scanner; import java.util.regex.Pattern; public class Main { static String replaceAllPerLine(Pattern pattern, String value, String replacement) { final StringBuilder result = new StringBuilder(); try (Scanner scanner = new Scanner(value)) { while (scanner.hasNextLine()) { final String line = scanner.nextLine(); result.append(pattern.matcher(line).replaceAll(replacement)); result.append("\n"); }/* w w w . j av a2 s.co m*/ } return result.toString(); } }