用于匹配假名 + 的多个条件的正则表达式汉字
我正在尝试编写一个正则表达式来匹配基于汉字字符串的所有单词。
例如,匹配文学生高
可以返回诸如文学、学生、高い等
之类的选项
,目前我只能返回输入汉字的完全匹配:
/^ [学生文高]+$/
但我还想包括具有这些字符 ([ぁ-んァ-ン]
) 的记录。
当我尝试结合这两个条件时,我最终匹配了所有内容。
/^[学生文高][ぁ-んァ-ン]+$/
<-- 这是理想的,因为它符合这两个条件。
基本上,“必须包含学生文高
,但也可以包含ぁ-んァ-ン
,而不必只包含ぁ-んァ-ン
对于那些
不太熟悉日语的人,一个更英语的示例可能是:搜索所有具有 test
的单词,并且我想在结果中包含数字,但不允许仅匹配数字,
例如, 测试
match 可以返回 test1,test2
但绝不只是 1
或 2
。
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该有效:
/^[あ-んア-ン]*([学生文高][あ-んア-ン]*)+$/
它在开头匹配零个或多个假名,然后是包含一个汉字和零个或多个假名的一组或多组。
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.