当前位置:网站首页>JS regular détermine si le nom de domaine ou le chemin de port IP est correct
JS regular détermine si le nom de domaine ou le chemin de port IP est correct
2022-04-23 15:47:00 【Victoria Junior...】
AdoptionjsPour juger régulièrementipChemin du porthttp://127.0.0.1:3000/listOuhttps://www.baidu.com:8080/listOui Non
const reg = new RegExp(/^http(s)?:\/\/((www\.)?[a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9]{0,62})|(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[0-9])\.((1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.){2}(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d))\:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])\/+[a-zA-Z0-9]/)
reg.test(“https://www.aaaa.com:2000/105”) // true
reg.test(“https://127.0.0.1:2000/105”) // true
reg.test(“https://127.0.0.1:2000/System/list”) // true
reg.test(“https://127.0.0.1:2000/dict/list”) // true
reg.test(“http://127.0.0.1:2000/dict/list”) // true
L'intégralité de l'étalonnage url, Vous pouvez utiliser la méthode suivante pour extraire ip、Port.Chemin
// AccèsipAdresse、Port、Lu Jin
getUrlComponent (url) {
let res = {
}
if (url.indexOf('//') !== -1 || url.indexOf(':') !== -1 || url.indexOf('.') !== -1) {
// Ne pas intercepter http
let str = url.indexOf('//') !== -1 ? url.substr(url.indexOf('//') + 2) : url
res.ip = str.indexOf(':') !== -1 ? str.substr(0, str.indexOf(':')) : str.indexOf('/') !== -1 ? str.substr(0, str.indexOf('/')) : str
res.port = str.indexOf('/') !== -1 ? str.slice(str.indexOf(':') + 1, str.indexOf('/')) : str.substr(str.indexOf(':') + 1)
res.path = res.port !== '' && str.indexOf(res.port) !== -1 ? str.substr(str.indexOf(res.port) + res.port.length) : str.indexOf('/') !== -1 ? str.substr(str.indexOf('/')) : ''
}
return res
}
版权声明
本文为[Victoria Junior...]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231547082639.html
边栏推荐
- 时序模型:长短期记忆网络(LSTM)
- Spark 算子之groupBy使用
- Application of Bloom filter in 100 million flow e-commerce system
- Merging of Shanzhai version [i]
- One brush 312 - simple repetition set - Sword finger offer 03 Duplicate number in array (E)
- 使用 Bitnami PostgreSQL Docker 镜像快速设置流复制集群
- leetcode-374 猜数字大小
- 大厂技术实现 | 行业解决方案系列教程
- 幂等性的处理
- The principle and common methods of multithreading and the difference between thread and runnable
猜你喜欢
MySQL Cluster Mode and application scenario
For examination
Why disable foreign key constraints
MySQL optimistic lock to solve concurrency conflict
c语言---字符串+内存函数
IronPDF for .NET 2022.4.5455
MetaLife与ESTV建立战略合作伙伴关系并任命其首席执行官Eric Yoon为顾问
CVPR 2022 quality paper sharing
C, calculation method and source program of bell number
为啥禁用外键约束
随机推荐
Special analysis of China's digital technology in 2022
fatal error: torch/extension. h: No such file or directory
Cookie&Session
VIM specifies the line comment and reconciliation comment
ICE -- 源码分析
【开源工具分享】单片机调试助手(示波/改值/日志) - LinkScope
Go language slice, range, set
Basic greedy summary
使用 Bitnami PostgreSQL Docker 镜像快速设置流复制集群
Recommended search common evaluation indicators
MetaLife与ESTV建立战略合作伙伴关系并任命其首席执行官Eric Yoon为顾问
【自娱自乐】构造笔记 week 2
Fastjon2 here he is, the performance is significantly improved, and he can fight for another ten years
Neodynamic Barcode Professional for WPF V11.0
C language --- string + memory function
Temporal model: long-term and short-term memory network (LSTM)
Upgrade MySQL 5.1 to 5.67
幂等性的处理
MySQL集群模式与应用场景
基础贪心总结