commit: 1bd56a552a157a9d170e9653b9a3f8e3a5802ae4
parent ab58d24c038e4de51dfb9913b88dbca1fc67d53d
Author: Egor Kislitsyn <egor@kislitsyn.com>
Date: Thu, 21 Feb 2019 17:25:12 +0700
update hashtag regex
Diffstat:
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/lib/auto_linker/parser.ex b/lib/auto_linker/parser.ex
@@ -25,7 +25,6 @@ defmodule AutoLinker.Parser do
~s{, work <a href="#" class="phone-number" data-phone="5555555555">(555) 555-5555</a>}
"""
- # @invalid_url ~r/\.\.+/
@invalid_url ~r/(\.\.+)|(^(\d+\.){1,2}\d+$)/
@match_url ~r{^[\w\.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+$}
@@ -45,7 +44,7 @@ defmodule AutoLinker.Parser do
# https://www.w3.org/TR/html5/forms.html#valid-e-mail-address
@match_email ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/u
- @match_hashtag ~r/^(?<tag>\#\w+)/u
+ @match_hashtag ~r/^(?<tag>\#[[:word:]_]*[[:alpha:]_ยท][[:word:]_]*)/u
@prefix_extra [
"magnet:?",
@@ -362,11 +361,8 @@ defmodule AutoLinker.Parser do
def match_hashtag(buffer) do
case Regex.run(@match_hashtag, buffer, capture: [:tag]) do
- [hashtag] ->
- if Regex.match?(~r/#\d+$/, hashtag), do: nil, else: hashtag
-
- _ ->
- nil
+ [hashtag] -> hashtag
+ _ -> nil
end
end