Can a URL contain a semicolon and still be valid?
我正在使用正则表达式将纯文本URL转换为可点击的链接。
但是,有时在文本正文中,URL每行枚举一个URL,并在末尾加一个分号。真实URL不包含任何";"。
1 2 3 | http://www.aaa.org/pressdetail.asp?PRESS_REL_ID=275; http://www.aaa.org/pressdetail.asp?PRESS_REL_ID=123; http://www.aaa.org/pressdetail.asp?PRESS_REL_ID=124 |
是否允许在URL中使用分号(;),或者可以将分号视为URL末尾的标记?怎么适合我的正则表达式?
保留分号,并且只能用于特殊目的(取决于方案)。
第2.2节:
Many URL schemes reserve certain
characters for a special meaning:
their appearance in the
scheme-specific part of the URL has a
designated semantics. If the character
corresponding to an octet is
reserved in a scheme, the octet must
be encoded. The characters";",
"/","?",":","@","=" and"&" are
the characters which may be
reserved for special meaning within a
scheme. No other characters may be
reserved within a scheme.
W3C鼓励CGI程序接受;也
分号是合法的URI字符;它属于子定界符类别:http://www.ietf.org/rfc/rfc3986.txt
但是,规范指出半色对于特定的URI是否合法取决于该URI的方案或生产者。因此,如果使用这些链接的站点不允许使用分号,则它们在特定情况下无效。
n
http://www.ietf.org/rfc/rfc3986.txt涵盖了URL以及可能以未编码形式出现的字符。鉴于包含分号的URL在浏览器中可以正常工作,因此您的代码应支持它们。
n
n