编辑代码

import java.util.regex.Matcher;
import java.util.regex.Pattern;


class Main {
	public static void main(String[] args) {
        String text = "(01)16973133332007(11)20220822(17)20240822(10)20220822P(21)4521453";

        System.out.println(findStr(text, "\\(01\\)([A-Za-z0-9]+)"));
        System.out.println(findStr(text, "\\(11\\)([A-Za-z0-9]+)"));
        System.out.println(findStr(text, "\\(17\\)([A-Za-z0-9]+)"));
        System.out.println(findStr(text, "\\(10\\)([A-Za-z0-9]+)"));
        System.out.println(findStr(text, "\\(21\\)([A-Za-z0-9]+)"));
     
	}

    static String findStr(String text, String regex) {
        System.out.println("exec findStr:" + regex);
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(text);
        while (matcher.find()) {
            return matcher.group(1);
        }
        return null;
    }
}