public class Demo07 { public static void main(String[] args) { // 现有字符串 String info = '古力娜扎ai8888迪丽热巴999aa5566马尔扎哈fbbfsfs425425卡尔扎巴';

    // 1、使用正则表达式,将字符串中的,非中文字符替换为'-'
    System.out.println(info.replaceAll('[^\u4e00-\u9fa5]+', '-'));
    
    // 2、使用正则表达式,将字符串中的,中文人名获取出来
    String[] arr = info.split('[^\u4e00-\u9fa5]+');
    for (String str : arr) {
        System.out.println(str);
    }
}

}

Java正则表达式实战:字符串处理与人名提取

原文地址: https://www.cveoy.top/t/topic/ntMy 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录