Home > Software engineering >  How can I RegExp for Unicode Blocks in flutter/dart?
How can I RegExp for Unicode Blocks in flutter/dart?

Time:12-02

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: 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?

CodePudding user response:

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 - !
  • Related