Hashtag regex updated. Moved to versione 1.0.1

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/social-networking/social-util-library@131216 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-09-08 12:45:08 +00:00
parent e1d7765878
commit 37eef5e954
4 changed files with 27 additions and 2 deletions

View File

@ -1,4 +1,8 @@
<ReleaseNotes>
<Changeset component="org.gcube.socialnetworking.social-util-library.1-0-1"
date="2016-10-01">
<Change>Hashtag regular expression updated (See ticket #4937)</Change>
</Changeset>
<Changeset component="org.gcube.socialnetworking.social-util-library.1-0-0"
date="2016-06-01">
<Change>First Release</Change>

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.socialnetworking</groupId>
<artifactId>social-util-library</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
<name>social-util-library</name>
<description>
The social-util-library contains utility functions that can be used by the social-networking portlets.

View File

@ -35,6 +35,12 @@ public class Utils {
* logger
*/
private static final Logger logger = LoggerFactory.getLogger(Utils.class);
/**
* Hashtag regex enhanced for ticket #4937
* If you want to accept hashtags of type #X, then you will need to use ^#\\w*[.]*\\w+|\\s#\\w*[.]*\\w+
*/
private static final String HASHTAG_REGEX = "^#\\w+[.]*\\w+|\\s#\\w+[.]*\\w+";
/**
*
@ -129,7 +135,7 @@ public class Utils {
*/
public static List<String> getHashTags(String postText) {
List<String> hashtags = new ArrayList<>();
Pattern MY_PATTERN = Pattern.compile("^#\\w+|\\s#\\w+");
Pattern MY_PATTERN = Pattern.compile(HASHTAG_REGEX);//Pattern.compile("^#\\w+|\\s#\\w+");
Matcher matcher = MY_PATTERN.matcher(postText);
while (matcher.find()) {
hashtags.add("#"+matcher.group().replace(" ", "").replace("#", ""));

View File

@ -0,0 +1,15 @@
package org.gcube.social_networking.socialutillibrary;
import java.util.List;
public class TestUnit {
//@Test
public void testHashtag() {
String text = "This is a test with hashtag #T6 and #T6.1 but also #T6. that has '.' that is useless.";
List<String> hashtags = Utils.getHashTags(text);
System.out.println("Hashtags are " + hashtags);
}
}