function toHalfWidthBrackets(str) {
return str.replace(/[\uff08\uff09\u3008\u3009]/g, function(match) {
switch(match) {
case '\uff08': // 全角左括号
return '(';
case '\uff09': // 全角右括号
return ')';
case '\u3008': // 全角左中括号
return '[';
case '\u3009': // 全角右中括号
return ']';
}
});
}
// 示例使用
const fullWidthStr = '([]])'; // 全角括号
const halfWidthStr = toHalfWidthBrackets(fullWidthStr); // 转换为半角括号
console.log(halfWidthStr); // 输出: ()[]