当前位置:网站首页>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
边栏推荐
- ICE -- 源码分析
- Go语言数组,指针,结构体
- WPS brand was upgraded to focus on China. The other two domestic software were banned from going abroad with a low profile
- Upgrade MySQL 5.1 to 5.69
- Go language, condition, loop, function
- Today's sleep quality record 76 points
- CVPR 2022 quality paper sharing
- shell脚本中的DATE日期计算
- 字符串最后一个单词的长度
- c语言---字符串+内存函数
猜你喜欢
随机推荐
Basic concepts of website construction and management
leetcode-396 旋转函数
基础贪心总结
Deletes the least frequently occurring character in the string
Neodynamic Barcode Professional for WPF V11. 0
Config learning notes component
Application case of GPS Beidou high precision satellite time synchronization system
Upgrade MySQL 5.1 to 5.611
怎么看基金是不是reits,通过银行购买基金安全吗
Configuration of multi spanning tree MSTP
utils.DeprecatedIn35 因升级可能取消,该如何办
MySQL optimistic lock to solve concurrency conflict
The El tree implementation only displays a certain level of check boxes and selects radio
Single architecture system re architecture
建设星际计算网络的愿景
APISIX jwt-auth 插件存在错误响应中泄露信息的风险公告(CVE-2022-29266)
Go并发和通道
新动态:SmartMesh和MeshBox的合作新动向
【自娱自乐】构造笔记 week 2
Config组件学习笔记