Add Hashtag-Regex (IOS-141)
This commit is contained in:
parent
d9243c25ce
commit
e041a7e086
|
@ -103,10 +103,12 @@ class SearchResultsOverviewTableViewController: UIViewController, NeedsDependenc
|
|||
}
|
||||
}
|
||||
|
||||
//TODO: Check for Hashtag-Regex!
|
||||
if searchText.starts(with: "#") && searchText.length > 1 {
|
||||
snapshot.appendItems([.default(.showHashtag(hashtag: searchText.replacingOccurrences(of: "#", with: "")))],
|
||||
toSection: .default)
|
||||
} else if searchText.length > 1, let hashtagRegex = try? NSRegularExpression(pattern: MastodonRegex.Search.hashtag, options: .caseInsensitive), hashtagRegex.firstMatch(in: searchText, range: NSRange(location: 0, length: searchText.length-1)) != nil {
|
||||
snapshot.appendItems([.default(.showHashtag(hashtag: searchText.replacingOccurrences(of: "#", with: "")))],
|
||||
toSection: .default)
|
||||
}
|
||||
|
||||
if searchText.length > 1,
|
||||
|
|
|
@ -25,6 +25,15 @@ public enum MastodonRegex {
|
|||
|
||||
public enum Search {
|
||||
public static let username = "^@?[a-z0-9_-]+(@[\\S]+)?$"
|
||||
|
||||
/// See: https://github.com/mastodon/mastodon/blob/main/app/javascript/mastodon/utils/hashtags.ts
|
||||
public static var hashtag: String {
|
||||
let word = "\\p{L}\\p{M}\\p{N}\\p{Pc}"
|
||||
let alpha = "\\p{L}\\p{M}"
|
||||
let hashtag_separators = "_\\u00b7\\u200c"
|
||||
|
||||
return "^(([\(word)_][\(word)\(hashtag_separators)]*[\(alpha)\(hashtag_separators)][\(word)\(hashtag_separators)]*[\(word)_])|([\(word)_]*[\(alpha)][\(word)_]*))$"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue