Java正则表达式匹配字符串不含中文逗号
使用以下正则表达式来匹配一个字符串不能含有中文逗号:\n\njava\nString regex = "^[^,]*$";\n\n\n解释:\n- ^ 表示字符串的开始;\n- [^,] 表示除中文逗号之外的任意字符;\n- * 表示前面的字符可以出现任意次数;\n- $ 表示字符串的结束。\n\n使用示例:\n\njava\nString str = "Hello,World!"; // 含有英文逗号\nboolean hasChineseComma = str.matches("^[^,]*$");\nSystem.out.println(hasChineseComma); // 输出 true\n\nstr = "你好,世界!"; // 含有中文逗号\nhasChineseComma = str.matches("^[^,]*$");\nSystem.out.println(hasChineseComma); // 输出 false\n
原文地址: https://www.cveoy.top/t/topic/pZnA 著作权归作者所有。请勿转载和采集!