gpt4 book ai didi

javascript - 从 Javascript 中的一系列字符中检测一个 unicode 字符(汉字)?

转载 作者:行者123 更新时间:2023-11-29 10:23:17 37 4
gpt4 key购买 nike

我正在尝试读取输入并仅在它是日文汉字时才传递它。根据http://www.rikai.com/library/kanjitables/kanji_codes.unicode.shtml,这意味着 Angular 色介于 4e00 和 9faf 之间。

是否可以使用 Javascript 来测试这个范围?

最佳答案

/[\u4e00-\u9faf]+/ 应该这样做。匹配 4e00 - 9faf 范围内的一个或多个字符。

来自MDN documentation :

\uhhhh Matches the character with the code hhhh (four hexadecimal digits).

所以在你的情况下,如果你想测试整个字符串,你可能想要:

if(/^[\u4e00-\u9faf]+$/.test(str)) {
// str is a kanji
}

关于javascript - 从 Javascript 中的一系列字符中检测一个 unicode 字符(汉字)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7150633/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com