added method Set<String> getMentionedUsernames
This commit is contained in:
parent
b8e1f20d97
commit
c1a78e8724
|
@ -3,7 +3,9 @@ package org.gcube.social_networking.socialutillibrary;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -41,6 +43,8 @@ public class Utils {
|
|||
*/
|
||||
|
||||
private static final String HASHTAG_REGEX = "^#\\w+([-_.]?\\w+)*|\\s#\\w+([-_.]?\\w+)*|(?<=[\\[({])#\\w+([-_.]?\\w+)";
|
||||
|
||||
private static final String MENTIONS_REGEX = "^@\\w+([-_.]?\\w+)*|\\s@\\w+([-_.]?\\w+)*|(?<=[\\[({])@\\w+([-_.]?\\w+)";
|
||||
|
||||
/**
|
||||
* IPv4 regex
|
||||
|
@ -80,6 +84,20 @@ public class Utils {
|
|||
sb.append("<span style=\"color:gray; font-size:12px;\">shared </span><a class=\"link\" href=\"").append(url).append("\" target=\"_blank\">").append("a file.").append("</a> ").toString();
|
||||
return sb.toString();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param postText
|
||||
* @return a set containing the list of mentions found
|
||||
*/
|
||||
public static Set<String> getMentionedUsernames(String postText) {
|
||||
Set<String> mentions = new HashSet<>();
|
||||
Pattern MY_PATTERN = Pattern.compile(MENTIONS_REGEX);
|
||||
Matcher matcher = MY_PATTERN.matcher(postText);
|
||||
while (matcher.find()) {
|
||||
mentions.add(matcher.group());
|
||||
}
|
||||
return mentions;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue