diff options
author | 2021-07-29 13:18:22 +0200 | |
---|---|---|
committer | 2021-07-29 13:18:22 +0200 | |
commit | a940a520d301d00f42012743b3999a73f7180848 (patch) | |
tree | 50bdd749381d6f773df46dbc4cc33a9b533a4e7b /internal/util/regexes.go | |
parent | Link parsing (#120) (diff) | |
download | gotosocial-a940a520d301d00f42012743b3999a73f7180848.tar.xz |
Link hashtag bug (#121)
* link + hashtag bug
* remove printlns
* tidy up some duplicated code
Diffstat (limited to 'internal/util/regexes.go')
-rw-r--r-- | internal/util/regexes.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/internal/util/regexes.go b/internal/util/regexes.go index 1ca34708f..c03fd878c 100644 --- a/internal/util/regexes.go +++ b/internal/util/regexes.go @@ -30,25 +30,26 @@ const ( ) var ( - mentionNameRegexString = `^@([a-zA-Z0-9_]+)(?:@([a-zA-Z0-9_\-\.]+)?)$` + mentionNameRegexString = `^@(\w+)(?:@([a-zA-Z0-9_\-\.]+)?)$` // mention name regex captures the username and domain part from a mention string // such as @whatever_user@example.org, returning whatever_user and example.org (without the @ symbols) mentionNameRegex = regexp.MustCompile(mentionNameRegexString) // mention regex can be played around with here: https://regex101.com/r/qwM9D3/1 - mentionFinderRegexString = `(?: |^|\W)(@[a-zA-Z0-9_]+(?:@[a-zA-Z0-9_\-\.]+)?)(?:[^a-zA-Z0-9]|\W|$)?` + mentionFinderRegexString = `(?:\B)(@\w+(?:@[a-zA-Z0-9_\-\.]+)?)(?:\B)?` mentionFinderRegex = regexp.MustCompile(mentionFinderRegexString) - // hashtag regex can be played with here: https://regex101.com/r/Vhy8pg/1 - hashtagFinderRegexString = fmt.Sprintf(`(?:\b)?#(\w{1,%d})(?:\b)`, maximumHashtagLength) - hashtagFinderRegex = regexp.MustCompile(hashtagFinderRegexString) + // hashtag regex can be played with here: https://regex101.com/r/bPxeca/1 + hashtagFinderRegexString = fmt.Sprintf(`(?:^|\n|\s)(#[a-zA-Z0-9]{1,%d})(?:\b)`, maximumHashtagLength) + // HashtagFinderRegex finds possible hashtags in a string. + // It returns just the string part of the hashtag, not the # symbol. + HashtagFinderRegex = regexp.MustCompile(hashtagFinderRegexString) - // emoji shortcode regex can be played with here: https://regex101.com/r/zMDRaG/1 - emojiShortcodeRegexString = fmt.Sprintf(`[a-z0-9_]{2,%d}`, maximumEmojiShortcodeLength) + emojiShortcodeRegexString = fmt.Sprintf(`\w{2,%d}`, maximumEmojiShortcodeLength) emojiShortcodeValidationRegex = regexp.MustCompile(fmt.Sprintf("^%s$", emojiShortcodeRegexString)) // emoji regex can be played with here: https://regex101.com/r/478XGM/1 - emojiFinderRegexString = fmt.Sprintf(`(?: |^|\W)?:(%s):(?:\b|\r)?`, emojiShortcodeRegexString) + emojiFinderRegexString = fmt.Sprintf(`(?:\B)?:(%s):(?:\B)?`, emojiShortcodeRegexString) emojiFinderRegex = regexp.MustCompile(emojiFinderRegexString) // usernameRegexString defines an acceptable username on this instance |