用于匹配假名 + 的多个条件的正则表达式汉字

发布于 2025-01-10 04:37:17 字数 574 浏览 3 评论 0原文

我正在尝试编写一个正则表达式来匹配基于汉字字符串的所有单词。

例如,匹配文学生高可以返回诸如文学、学生、高い等之类的选项

,目前我只能返回输入汉字的完全匹配:

/^ [学生文高]+$/ 但我还想包括具有这些字符 ([ぁ-んァ-ン]) 的记录。

当我尝试结合这两个条件时,我最终匹配了所有内容。

/^[学生文高][ぁ-んァ-ン]+$/ <-- 这是理想的,因为它符合这两个条件。

基本上,“必须包含学生文高,但也可以包含ぁ-んァ-ン,而不必只包含ぁ-んァ-ン 对于那些

不太熟悉日语的人,一个更英语的示例可能是:搜索所有具有 test 的单词,并且我想在结果中包含数字,但不允许仅匹配数字,

例如, 测试 match 可以返回 test1,test2 但绝不只是 12

I am trying to write a regex that match all words based on a kanji string.

For example, matching 文学生高 could return options like 文学、学生、高い,etc

currently, I have can return only exact match on kanji entered:

/^[学生文高]+$/ but I would like to include records that have these chars ([ぁ-んァ-ン]) as well.

When I try to combine the two conditions, I end up matching everything.

/^[学生文高][ぁ-んァ-ン]+$/ <-- this is ideal, as it matches on both of those conditions.

basically, something that "must include 学生文高 but can also include ぁ-んァ-ン without having only including ぁ-んァ-ン.

For those not so familiar with Japanese, a more English example could be: searching for all words that have test and I would like to include numbers in results, but disallow matching just numbers.

For example, test match could return test1,test2 but never just 1 or 2.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冬天的雪花 2025-01-17 04:37:17

这应该有效: /^[あ-んア-ン]*([学生文高][あ-んア-ン]*)+$/

它在开头匹配零个或多个假名,然后是包含一个汉字和零个或多个假名的一组或多组。

This should work: /^[あ-んア-ン]*([学生文高][あ-んア-ン]*)+$/

It matches zero or more kana at the start, then one or more groups containing one kanji and zero or more kana.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文