Commit 1bd56a55 authored by minibikini's avatar minibikini 😷

update hashtag regex

parent ab58d24c
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment