请参阅RFC 3986。
fragment = *( pchar / "/" / "?" )
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
所以您可以使用 !
, $
, &
, '
, (
, )
, *
, +
, ,
, ;
, =
, 与类似于 %[0-9a-fA-F]{2}
、类似于 [a-zA-Z0-9]
的内容匹配、-
, .
, _
, ~
, :
, @
, /
和 ?
。
https://www.rfc-editor.org/rfc/rfc3986#section-3.5:
fragment = *( pchar / "/" / "?" )
并且
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
pct-encoded = "%" HEXDIG HEXDIG
综合来看,根据RFC标准,该片段不能包含#
、原始%
、^
、[
、]
、{
、}
、\
、"
、<
和 >
。
)”和“空格( )”。因此,not-list 中所有可打印的(7比特)美国标准信息交换码字符列表为:“#%< >[\]^
{|}”。 - GitaarLAB另外还有一份RFC提到了这个问题:RFC-1738
URL schemeparts for ip based protocols:
HTTP
httpurl = "http://" hostport [ "/" hpath [ "?" search ]]
hpath = hsegment *[ "/" hsegment ]
hsegment = *[ uchar | ";" | ":" | "@" | "&" | "=" ]
search = *[ uchar | ";" | ":" | "@" | "&" | "=" ]
%
只能作为转义字符使用。使用%25
对单个%
进行编码。 - gioele