This is what I use to remove emojis and so far it has shown to allow all other alphabets.
private static String remove_Emojis(String name)
{
//we will store all the letters in this array
ArrayList<Character> nonEmoji = new ArrayList<>();
// and when we rebuild the name we will put it in here
String newName = "";
// we are going to loop through checking each character to see if its an emoji or not
for (int i = 0; i < name.length(); i++)
{
if (Character.isLetterOrDigit(name.charAt(i)))
{
nonEmoji.add(name.charAt(i));
}
else
{
// this is just a 2nd check in case the other method didn't allow some letter
if (Build.VERSION.SDK_INT > 18)
{
if (Character.isAlphabetic(name.charAt(i)))
{
nonEmoji.add(name.charAt(i));
}
}
}
if (name.charAt(i) == ' ')// may want to consider adding or '-' or '\''
{
nonEmoji.add(i);// just add it
}
if (name.charAt(i) == '@' && !name.contains(" "))// I put this in for email addresses
{
nonEmoji.add('@');
}
}
// finally just loop through building it back out
for (int i = 0; i < nonEmoji.size(); i++) {
newName += nonEmoji.get(i);
}
return newName;
}
Using emoji-java i've wrote a simple method that removes all emojis including fitzpatrick modifiers. Requires an external library but easier to maintain than those monster regexes.
you can do it like this
This is what I use to remove emojis and so far it has shown to allow all other alphabets.
You can generate your own regex whenever the spec changes.
This tool (screenshot here).
For utf-8/32 mode (stringed), expanded mode :
For utf-16 mode (stringed), compressed mode :
Just to use regex to solve it:
You can find it in
http://www.regular-expressions.info/unicode.html
https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#OTHER_SYMBOL
Using emoji-java i've wrote a simple method that removes all emojis including fitzpatrick modifiers. Requires an external library but easier to maintain than those monster regexes.
Use:
The best regex for extracting ALL emoji is this:
It identifies many single-char emoji that the other answers do not account for. For more information about how this regex works, take a look at this post. https://medium.com/@thekevinscott/emojis-in-javascript-f693d0eb79fb#.enomgcu63