常用正则
URL 匹配
- 协议:
((https?|ftp):\/\/)?
- 域名:
- 单部分:
[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*
- 整体:
[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*(\.[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)*
- 单部分:
- 端口:
(:\d+)?
- 路径:
(\/\w*)*
- 查询字符串:
([\?&]\w+=\w*)*
- 哈希:
(#\w*)?
js
/^((https?|ftp):\/\/)?[a-zA-Z0-9](-[a-zA-Z0-9])*(\.[a-zA-Z0-9](-[a-zA-Z0-9])*)*(:\d+)?(\/\w*)*([\?&]\w+=\w*)*$/;