我正在尝试为这样的链接创建正则表达式
<link rel="canonical" href="https://example.com/locs/my-locs" />
我想让我的-locs作为正则表达式
(?:[^/][\d\w\.]+)$(?:")这是我一直在尝试的
发布于 2021-03-07 18:45:34
发布于 2021-03-07 18:42:00
下面的代码还确保它以http或https开头,并对urls进行了其他几个检查:https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)
发布于 2021-03-08 05:36:36
使用
(?<=\/)[\w-]+(?="\s*\/>)参见proof。
说明
--------------------------------------------------------------------------------
(?<= look behind to see if there is:
--------------------------------------------------------------------------------
\/ '/'
--------------------------------------------------------------------------------
) end of look-behind
--------------------------------------------------------------------------------
[\w-]+ any character of: word characters (a-z, A-
Z, 0-9, _), '-' (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
" '"'
--------------------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
--------------------------------------------------------------------------------
\/ '/'
--------------------------------------------------------------------------------
> '>'
--------------------------------------------------------------------------------
) end of look-aheadhttps://stackoverflow.com/questions/66515560
复制相似问题