summaryrefslogtreecommitdiffstats
path: root/model/utils.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-01-27 07:38:10 -0500
committerJoram Wilander <jwawilander@gmail.com>2016-01-27 07:38:10 -0500
commite5ed90821e6bb25c27e5627cf289df41cbcb1793 (patch)
tree98446b1586e29afbedb92f9a63446d12a72f8b83 /model/utils.go
parentefc4d239e14707de27b149b76f1dd4065838410c (diff)
parent97ede2a428faf3a62ce0140e51ed591e261c09a1 (diff)
downloadchat-e5ed90821e6bb25c27e5627cf289df41cbcb1793.tar.gz
chat-e5ed90821e6bb25c27e5627cf289df41cbcb1793.tar.bz2
chat-e5ed90821e6bb25c27e5627cf289df41cbcb1793.zip
Merge pull request #1984 from hmhealey/plt1103
PLT-1103 Updated serverside hashtag regex to ignore more punctuation around words
Diffstat (limited to 'model/utils.go')
-rw-r--r--model/utils.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/model/utils.go b/model/utils.go
index 70b7e3bbd..719a2ad1b 100644
--- a/model/utils.go
+++ b/model/utils.go
@@ -298,8 +298,9 @@ func Etag(parts ...interface{}) string {
}
var validHashtag = regexp.MustCompile(`^(#[A-Za-zäöüÄÖÜß]+[A-Za-z0-9äöüÄÖÜß_\-]*[A-Za-z0-9äöüÄÖÜß])$`)
-var puncStart = regexp.MustCompile(`^[.,()&$!\?\[\]{}':;\\]+`)
-var puncEnd = regexp.MustCompile(`[.,()&$#!\?\[\]{}';\\]+$`)
+var puncStart = regexp.MustCompile(`^[.,()&$!\?\[\]{}':;\\<>\-+=%^*|]+`)
+var hashtagStart = regexp.MustCompile(`^#{2,}`)
+var puncEnd = regexp.MustCompile(`[.,()&$#!\?\[\]{}':;\\<>\-+=%^*|]+$`)
func ParseHashtags(text string) (string, string) {
words := strings.Fields(text)
@@ -307,8 +308,13 @@ func ParseHashtags(text string) (string, string) {
hashtagString := ""
plainString := ""
for _, word := range words {
+ // trim off surrounding punctuation
word = puncStart.ReplaceAllString(word, "")
word = puncEnd.ReplaceAllString(word, "")
+
+ // and remove extra pound #s
+ word = hashtagStart.ReplaceAllString(word, "#")
+
if validHashtag.MatchString(word) {
hashtagString += " " + word
} else {