Java Regex String Replace All replaceAllPerLine(Pattern pattern, String value, String replacement)

Here you can find the source of replaceAllPerLine(Pattern pattern, String value, String replacement)

Description

replace All Per Line

License

Open Source License

Declaration

static String replaceAllPerLine(Pattern pattern, String value, String replacement) 

Method Source Code


//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();
    }
}

Related

  1. replaceAll(String text, Pattern pattern, String replace)
  2. replaceAll(StringBuilder sb, String regex, String replacement)
  3. replaceAllBackreference(String text, String regex, String replacement)
  4. replaceAllIgnoreCase(String source, String oldstring, String newstring)
  5. replaceAllLiteral(@Nonnull String value, @Nonnull Pattern pattern, @Nonnull String replace)
  6. replaceAllStrictly(String src, String search, String replacement, boolean entirelyMatch, boolean caseSensitive)
  7. replaceAllTotal(String what, Pattern p, String replacement)
  8. replaceAllTotal(String what, String expr, String replacement)