Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8396241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:29:19+00:00 2026-06-09T20:29:19+00:00

I have a program that is parsting tweets in real time from the twitter

  • 0

I have a program that is parsting tweets in real time from the twitter stream api. Before storing them, I am encoding them as utf8. Certain characters end up appearing in the string as ?, ??, or ??? instead of their respective unicode codes and cause problems. Upon further investigation, I found that the problematic characters are from the “emoticon” block, U+1F600 – U+1F64F, and the “Miscellaneous Symbols And Pictographs” block, U+1F300 – U+1F5FF. I tried removing, but was unsuccessful as the matcher ended up replacing almost every character in the string, not just my desired unicode range.

String utf8tweet = "";
        try {
            byte[] utf8Bytes = status.getText().getBytes("UTF-8");

            utf8tweet = new String(utf8Bytes, "UTF-8");

        } 
        catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
Pattern unicodeOutliers = Pattern.compile("[\\u1f300-\\u1f64f]", Pattern.UNICODE_CASE | Pattern.CANON_EQ | Pattern.CASE_INSENSITIVE);
Matcher unicodeOutlierMatcher = unicodeOutliers.matcher(utf8tweet);
utf8tweet = unicodeOutlierMatcher.replaceAll(" ");

What can I do to remove these characters?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:29:20+00:00Added an answer on June 9, 2026 at 8:29 pm

    In the regex pattern add the negation operator ^. For filtering printable characters you could use the following expression [^\\x00-\\x7F] and you should get the desired result.

    import java.io.UnsupportedEncodingException;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    public class UTF8 {
        public static void main(String[] args) {
            String utf8tweet = "";
            try {
                byte[] utf8Bytes = "#Hello twitter  How are you?".getBytes("UTF-8");
    
                utf8tweet = new String(utf8Bytes, "UTF-8");
    
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            Pattern unicodeOutliers = Pattern.compile("[^\\x00-\\x7F]",
                    Pattern.UNICODE_CASE | Pattern.CANON_EQ
                            | Pattern.CASE_INSENSITIVE);
            Matcher unicodeOutlierMatcher = unicodeOutliers.matcher(utf8tweet);
    
            System.out.println("Before: " + utf8tweet);
            utf8tweet = unicodeOutlierMatcher.replaceAll(" ");
            System.out.println("After: " + utf8tweet);
        }
    }
    

    Results in the following output:

    Before: #Hello twitter  How are you?
    After: #Hello twitter   How are you?
    

    EDIT

    To explain further, you could also keep expressing the range with the \u form in the following way [^\\u0000-\\u007F], which will match all the characters which are not the first 128 UNICODE characters (the same as before). If you want to extend the range to support extra characters, you can do so using the UNICODE character list here.

    For example if you want to include vowels with accent (used in Spanish) you should extend the range to \u00FF, so you have [^\\u0000-\\u00FF] or [^\\x00-\\xFF]:

    Before: #Hello twitter  How are you? á é í ó ú
    After: #Hello twitter   How are you? á é í ó ú
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that gets a JSON from the server using getJSON and
I have a program that reads from a file that grabs 4 bytes from
I have a simple parsing program that takes a few files and combines them.
I have a program that receives something like this from a settings file: C:\Files\App
So we have a program that the user can use by copying text from
I have program that requires Python 3, but I develop Django and it uses
I have program that has a variable that should never change. However, somehow, it
I have program that runs fast enough. I want to see the number of
I have a program that saves an image in a local directory and then
I have a program that encrypts files, but adds the extension .safe to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.