Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emoji Regex #8

Open
febg11 opened this issue Jan 26, 2020 · 7 comments
Open

Emoji Regex #8

febg11 opened this issue Jan 26, 2020 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@febg11
Copy link

febg11 commented Jan 26, 2020

I was wondering if you could help me with blocking emojis from being typed into input boxes.

The emoji ๐ŸŒฌ๏ธ (and a few others) still get typed into input boxes that have been blacklisted with your regex.

   return BlacklistingTextInputFormatter(
        EmojiParser.REGEX_EMOJI
    );

They dont get typed but they get counted as input. E.g. if you have a hint in the text box (or character count) and type the emoji the hint will disappear and the character count will increase to 1. There is actually no input in the box, just empty space.

@febg11
Copy link
Author

febg11 commented Jan 26, 2020

If i get the string after typing them in the code unit field has [65039, 65039, 65039, 65039, 65039, 65039] as a value. This seems to be this
https://unicode-table.com/en/FE0F/

@febg11
Copy link
Author

febg11 commented Jan 26, 2020

Could you try and use this regex it seems to fix the problem https://github.com/mathiasbynens/emoji-regex/blob/master/index.js

@petehouston
Copy link
Owner

@febg11 it's kinda different, the regex by EmojiParser is to parse emoji, not to filter. If you want to filter emoji runes from TextField or similar widgets, you need to filter the \ufe0f character.

Use this

TextField(
  onChanged: (text) {
    print("Word count: " + text.length.toString());
  },
  inputFormatters: [
    BlacklistingTextInputFormatter(RegExp(
        r'(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]|\ufe0f)'
    ))
  ],
)

@febg11
Copy link
Author

febg11 commented Apr 4, 2020

Hi @petehouston

Sorry for not replying for a long time I only just got around to doing this. I have tested your regex which fixes a lot of my problems however it does not detect the English, Welsh and Scottish flags as well as the unofficial flags which can be seen on here.

This is part of my test that fails.

    String regexNew = r'(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]|\ufe0f)';
    RegExp regex = RegExp(regexNew);

    print("Starting british flags");
    String flags2 = "๐Ÿด๓ ง๓ ข๓ ฅ๓ ฎ๓ ง๓ ฟ๐Ÿด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟ๐Ÿด๓ ง๓ ข๓ ท๓ ฌ๓ ณ๓ ฟ";
    String flags2Output = flags2.replaceAll(regex, "");
    expect(flags2Output, "");
    print("Starting Unofficial Flags Emojis");
    String unofficialFlagsEmojis = "๐Ÿด๓ ข๓ ณ๓ ก๓ ซ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ข๓ น๓ ฟ๐Ÿด๓ ข๓ ณ๓ ข๓ ฉ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ข๓ ฐ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ฃ๓ ฏ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ฃ๓ ณ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ฃ๓ ฅ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ฃ๓ ซ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ฅ๓ ง๓ ฟ๐Ÿด๓ ข๓ ณ๓ ฅ๓ ธ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ฆ๓ ฐ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ง๓ ฃ๓ ฟ๐Ÿด๓ ข๓ ณ๓ จ๓ ฉ๓ ฟ๐Ÿด๓ ข๓ ณ๓ จ๓ ด๓ ฟ๐Ÿด๓ ข๓ ณ๓ ฉ๓ ฎ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ฌ๓ ฉ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ญ๓ ฃ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ญ๓ ง๓ ฟ๐Ÿด๓ ข๓ ณ๓ ญ๓ ฉ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ฎ๓ ฏ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ฎ๓ ณ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ฎ๓ ฅ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ฒ๓ ฉ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ฒ๓ ฃ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ณ๓ ณ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ณ๓ ฏ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ณ๓ ก๓ ฟ๐Ÿด๓ ข๓ ณ๓ ณ๓ ฅ๓ ฟ๐Ÿด๓ ข๓ ณ๓ ณ๓ ท๓ ฟ๐Ÿด๓ ข๓ ณ๓ ท๓ ง๓ ฟ";
    String unofficialFlagsEmojisOutput = unofficialFlagsEmojis.replaceAll(regex, "");
    expect(unofficialFlagsEmojisOutput, "");

I am not sure what the unofficial flags even are.

Could you help me adjust the regex to ensure that the British flags and possibly the unofficial flags are black listed in the regex.

Thank you so much for all you have done.

@petehouston
Copy link
Owner

Interesting. I will take a look on those emojis.

@febg11
Copy link
Author

febg11 commented Apr 17, 2020

Thanks Pete I really appreciate your help ๐Ÿ˜Š

@petehouston petehouston self-assigned this Apr 17, 2020
@petehouston petehouston added the bug Something isn't working label Apr 17, 2020
@febg11
Copy link
Author

febg11 commented May 28, 2020

Hi Pete did you manage to take a look at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants