title: Fast way to extract hashtags, user mentions and urls from tweet text?
body: <p>I'm trying to find a fast way to get an array of Strings made for each: 1- hashtags, 2- user mentions 3- urls in a tweet text. I have the tweets text in csv file.</p>
  
  <p>My way to solve the problem takes too long processing time and I wonder if I can optimize my code a bit. I will show my regex rules for each matching type but just not to post a long code I will show only how I'm matching the hashtags. The same technique is for urls and user mentions.</p>
  
  <p>Here it is:</p>
  
  <pre><code>public static String hashtagRegex = "^#\\w+|\\s#\\w+";
  public static Pattern hashtagPattern = Pattern.compile(hashtagRegex);
  
  public static String urlRegex = "http+://[\\S]+|https+://[\\S]+";
  public static Pattern urlPattern = Pattern.compile(urlRegex);
  
  public static String mentionRegex = "^@\\w+|\\s@\\w+";
  public static Pattern mentionPattern = Pattern.compile(mentionRegex);
  
  public static String[] getHashtag(String text) {
     String hashtags[];
     matcher = hashtagPattern.matcher(tweet.getText());
  
      if ( matcher.find() ) {
          hashtags = new String[matcher.groupCount()];
          for ( int i = 0; matcher.find(); i++ ) {
                      //Also i'm getting an ArrayIndexOutOfBoundsException
              hashtags[i] = matcher.group().replace(" ", "").replace("#", "");
          }
      }
  
     return hashtags;
  
  }
  </code></pre>