java hashtag using
2019. 7. 31. 17:57ㆍ99. 정리전 - IT/11. Java
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; } |