I recommend you filter each file and then compare the filtered output to each template. If an input file is to contain only non-negative integers, then you can use a simpler Pattern class object replace all matches with '0' and all non-matches with nothing. Then your two files will be equal.
Something like the following:
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.regex.Pattern;
public class Change {
static Pattern changeNumbers = Pattern.compile("[0-9]+", Pattern.MULTILINE);
static Pattern changeTabsBlanks = Pattern.compile("[ ]+", Pattern.MULTILINE);
public static String normalizeIntegerString (String str) {
str = changeNumbers.matcher(str).replaceAll("0");
str = changeTabsBlanks.matcher(str).replaceAll("");
return str;
}
public static void emitString (String strname, String str) {
System.err.println(String.format("%s length is %d", strname, str.length()));
System.err.println(str);
System.err.println("");
}
public static void main (String args[]) throws Exception {
String patternFilename = args[0];
String inputFilename = args[1];
String patternFileContent = new String(Files.readAllBytes(Paths.get(patternFilename)));
String inputFileContent = new String(Files.readAllBytes(Paths.get(inputFilename)));
String filteredInputFileContent = normalizeIntegerString(inputFileContent);
String filteredPatternFileContent = normalizeIntegerString(patternFileContent);
emitString("filteredInputFileContent", filteredInputFileContent);
emitString("filteredPatternFileContent", filteredPatternFileContent);
if (filteredInputFileContent.contentEquals(filteredPatternFileContent))
System.out.println("match");
else
System.out.println("mismatch");
}
}