1

I have some .NET RegExp code I am attempting to translate into Dart/Flutter. I see that Microsoft had some proprietary block names like "IsCJKSymbolsandPunctuation" but similar names exist here: https://www.regular-expressions.info/unicode.html#category. Nevertheless, both

    var something = "你好".replaceAll(RegExp(r"[\p{InCJK_Symbols_and_Punctuation}]", unicode: true), "");
    log(something);

and

    var something = "你好".replaceAll(RegExp(r"[\p{Han}]", unicode: true), "");
    log(something);

result in enter image description here

My ultimate target is

//        r"\p{IsCJKSymbolsandPunctuation}\p{IsEnclosedCJKLettersandMonths}\p{IsCJKCompatibility}\p{IsCJKUnifiedIdeographsExtensionA}\p{IsCJKUnifiedIdeographs}\p{IsCJKCompatibilityIdeographs}\p{IsCJKCompatibilityForms}";

Is the only way to enter in code points?

julemand101
  • 21,132
  • 4
  • 38
  • 37
tofutim
  • 21,324
  • 20
  • 81
  • 144

1 Answers1

0

You can use

var something = "你好".replaceAll(RegExp(r"\p{Script=Hani}", unicode: true), "");

\p{Script=Hani} will match any Chinese characters, same as \p{Han} in PCRE.

A Dart test:

String text = "Abc 123 - 你好!";
print(text.replaceAll(RegExp(r"\p{Script=Hani}", unicode: true), ""));

Output:

Abc 123 - !
Wiktor Stribiżew
  • 561,645
  • 34
  • 376
  • 476