如何将Hangul添加到这个正则表达式中?

时间:2021-05-09 03:57:46

I have this regex to detect alpha-numeric, Kanji, Katakana, and Hiragana. I would like to add Hangul to this, but I'm not sure of the range:

我有这个regex来检测字母数字、汉字、片假名和平假名。我想在这里加上Hangul,但是我不确定它的范围:

Regex.IsMatch(p.Name, @"^[a-zA-Z0-9ァ-ヾぁ-んー一-龠々]+$")

Regex.IsMatch(p。名字,@ " ^[a-zA-Z0-9ァ——ヾぁ——んー一——龠々]+ $”)

Thank you!

谢谢你!

1 个解决方案

#1


2  

There are three Unicode categories you may add to your regex to support Hangul:

您可以在regex中添加三个Unicode类别来支持Hangul:

\p{IsHangulSyllables}
\p{IsHangulCompatibilityJamo}
\p{IsHangulJamo}

You may add them to the end of the character class:

您可以将它们添加到角色类的末尾:

@"^[a-zA-Z0-9ァ-ヾぁ-んー一-龠々\p{IsHangulSyllables}\p{IsHangulCompatibilityJamo}\p{IsHangulJamo}]+$" 

To support all CJK chars, you may consider adding

为了支持所有的CJK chars,您可以考虑添加。

\p{IsCJKRadicalsSupplement}
\p{IsCJKSymbolsandPunctuation}
\p{IsEnclosedCJKLettersandMonths}
\p{IsCJKCompatibility}
\p{IsCJKUnifiedIdeographsExtensionA}
\p{IsCJKUnifiedIdeographs}
\p{IsCJKCompatibilityForms}

too.

了。

#1


2  

There are three Unicode categories you may add to your regex to support Hangul:

您可以在regex中添加三个Unicode类别来支持Hangul:

\p{IsHangulSyllables}
\p{IsHangulCompatibilityJamo}
\p{IsHangulJamo}

You may add them to the end of the character class:

您可以将它们添加到角色类的末尾:

@"^[a-zA-Z0-9ァ-ヾぁ-んー一-龠々\p{IsHangulSyllables}\p{IsHangulCompatibilityJamo}\p{IsHangulJamo}]+$" 

To support all CJK chars, you may consider adding

为了支持所有的CJK chars,您可以考虑添加。

\p{IsCJKRadicalsSupplement}
\p{IsCJKSymbolsandPunctuation}
\p{IsEnclosedCJKLettersandMonths}
\p{IsCJKCompatibility}
\p{IsCJKUnifiedIdeographsExtensionA}
\p{IsCJKUnifiedIdeographs}
\p{IsCJKCompatibilityForms}

too.

了。