lib/text_filtering: add kanjiRegex

This commit is contained in:
2025-05-16 17:05:57 +02:00
parent d7f7f9cd19
commit fc0956d5c3

View File

@@ -4,7 +4,7 @@
/// See https://www.regular-expressions.info/unicode.html
///
/// Remember to turn on the unicode flag when making a new RegExp.
const String rawKanjiRegex = r'\p{Script=Hani}';
const String rawCJKRegex = r'\p{Script=Hani}';
/// The string version of a regex that will match any katakana.
/// This includes the ranges (), ()
@@ -22,14 +22,22 @@ const String rawKatakanaRegex = r'\p{Script=Katakana}';
/// Remember to turn on the unicode flag when making a new RegExp.
const String rawHiraganaRegex = r'\p{Script=Hiragana}';
/// The string version of a regex that will match any kanji.
/// This includes the ranges (), ()
///
/// See https://www.regular-expressions.info/unicode.html
///
/// Remember to turn on the unicode flag when making a new RegExp.
const String rawKanjiRegex = r'[\u3400-\u4DB5\u4E00-\u9FCB\uF900-\uFA6A]';
final RegExp kanjiRegex = RegExp(rawKanjiRegex, unicode: true);
final RegExp cjkRegex = RegExp(rawCJKRegex, unicode: true);
final RegExp katakanaRegex = RegExp(rawKatakanaRegex, unicode: true);
final RegExp hiraganaRegex = RegExp(rawHiraganaRegex, unicode: true);
final RegExp kanjiRegex = RegExp(rawKanjiRegex, unicode: true);
final kanjiPattern = RegExp(r'[\u3400-\u4DB5\u4E00-\u9FCB\uF900-\uFA6A]');
List<String> filterKanjiSuggestions(String string) {
return kanjiPattern
return kanjiRegex
.allMatches(string)
.map((match) => match.group(0))
.where((element) => element != null)