有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (1) 个答案

  1. # 1 楼答案

    您可以使用这个正则表达式在group1和group2中捕获名字和姓氏

    CN=([a-zA-Z]+)\\,\s+([a-zA-Z]+)
    

    Demo

    Java代码

    String s = "CN=Belzile\\, Pierre,OU=LaptopUser,OU=Users,DC=Company,DC=local";
    Pattern p = Pattern.compile("CN=([a-zA-Z]+)\\\\,\\s+([a-zA-Z]+)");
    Matcher m = p.matcher(s);
    
    if(m.find()) {
        System.out.println(m.group(1) + " " + m.group(2));
    }
    

    打印您的预期输出

    Belzile Pierre