当前位置:网站首页>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
边栏推荐
- For examination
- One brush 314 sword finger offer 09 Implement queue (E) with two stacks
- Go concurrency and channel
- 考试考试自用
- String sorting
- 大型互联网为什么禁止ip直连
- s16. One click installation of containerd script based on image warehouse
- What if the package cannot be found
- Advantages, disadvantages and selection of activation function
- Redis master-slave replication process
猜你喜欢
Redis master-slave replication process
Codejock Suite Pro v20.3.0
C language --- advanced pointer
王启亨谈Web3.0与价值互联网“通证交换”
C#,贝尔数(Bell Number)的计算方法与源程序
Cookie&Session
多级缓存使用
Sorting and replying to questions related to transformer
Do we media make money now? After reading this article, you will understand
Temporal model: long-term and short-term memory network (LSTM)
随机推荐
C language --- advanced pointer
[self entertainment] construction notes week 2
CVPR 2022 优质论文分享
[backtrader source code analysis 18] Yahoo Py code comments and analysis (boring, interested in the code, you can refer to)
CAP定理
Introduction to dynamic programming of leetcode learning plan day3 (198213740)
幂等性的处理
Open source project recommendation: 3D point cloud processing software paraview, based on QT and VTK
开源项目推荐:3D点云处理软件ParaView,基于Qt和VTK
编译,连接 -- 笔记
Sorting and replying to questions related to transformer
Upgrade MySQL 5.1 to 5.67
MySQL optimistic lock to solve concurrency conflict
Cookie&Session
Modèle de Cluster MySQL et scénario d'application
多线程原理和常用方法以及Thread和Runnable的区别
【第5节 if和for】
utils.DeprecatedIn35 因升级可能取消,该如何办
Cookie&Session
腾讯Offer已拿,这99道算法高频面试题别漏了,80%都败在算法上