Appendix B: Parsing a URI Reference with a Regular Expression
附录B: 使用正则表达式解析URI引用
以下正则表达式可以将URI引用解析为其组件:
^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
12 3 4 5 6 7 8 9
组件对应:
$1= scheme:$2= scheme$3= //authority$4= authority$5= path$6= ?query$7= query$8= #fragment$9= fragment
示例: http://www.ics.uci.edu/pub/ietf/uri/#Related
- scheme =
http - authority =
www.ics.uci.edu - path =
/pub/ietf/uri/ - query = (undefined)
- fragment =
Related