When I run this code, it prints out only the groups found in the first pattern it matched per line. However, there are multiple strings I want to replace in each line and I want it to print out the specific groups for each string in the pattern it matched. How can I change it so that it prints out the groups specific to the patterns/strings it found in each line instead of printing only the groups in the first pattern match it found?
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.FileNotFoundException;
import java.io.File;
public class RealReadFile {
    private static final String fileName = "KLSadd.tex";
    private Scanner myFile = null;
    // No-args constructor, create a new scanner for the specific file defined
    // above
    public RealReadFile() throws FileNotFoundException {
        if (myFile == null)
            myFile = new Scanner(new File(fileName));
    }
    // One-arg constructor - the name of the file to open
    public RealReadFile(String name) throws FileNotFoundException {
        if (myFile != null)
            myFile.close();
        myFile = new Scanner(new File(name));
    }
    public boolean endOfFile() {    // Return true is there is no more input
        return !myFile.hasNext();   // hasNext() returns true if there is more input, so I negate it
    }
    public String nextLine() {
        return myFile.nextLine().trim();
    }
    public static void main(String[] args) throws FileNotFoundException {
        RealReadFile file = new RealReadFile();
        while(!file.endOfFile()) {
            String line = file.nextLine();
            Pattern cpochhammer = Pattern.compile("(\\(([^\\)]+)\\)_\\{?([^\\}]+)\\}?)");
            Matcher pochhammer = cpochhammer.matcher(line);
            while (pochhammer.find()){
                System.out.println(line);
                String line2=pochhammer.replaceAll("\\\\pochhammer{" + pochhammer.group(2) + "}{" + pochhammer.group(3) + "}");
                System.out.println(line2);
            }
        }
    }
}
 
     
     
    