js常用正则待完善
- 匹配中文和中文标点符号
/*
干货:/^[\u4e00-\u9fa5\uff00-\uffef]+$/
*/
function isChineseWithPunctuation(str) {
const regex = /^[\u4e00-\u9fa5\uff00-\uffef]+$/;
return regex.test(str);
}
// 测试示例
console.log(isChineseWithPunctuation("你好,世界!")); // true
console.log(isChineseWithPunctuation("你好,World!")); // false
console.log(isChineseWithPunctuation("Hello,World!")); // false
/*
\u4e00-\u9fa5: 是 Unicode 范围,表示中文字符的编码范围。
\uff00-\uffef: 是 Unicode 范围,表示全角字符(包括中文标点符号)的编码范围。
*/