当前位置:网站首页>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
边栏推荐
- Go language, condition, loop, function
- 编译,连接 -- 笔记
- PHP classes and objects
- Metalife established a strategic partnership with ESTV and appointed its CEO Eric Yoon as a consultant
- cadence SPB17.4 - Active Class and Subclass
- s16.基于镜像仓库一键安装containerd脚本
- Independent operation smart farm Innovation Forum
- IronPDF for .NET 2022.4.5455
- Accumulation of applet knowledge points
- Basic greedy summary
猜你喜欢
移动金融(自用)
Spark 算子之coalesce与repartition
Codejock Suite Pro v20. three
c语言---指针进阶
负载均衡器
MySQL Cluster Mode and application scenario
Mobile finance (for personal use)
使用 Bitnami PostgreSQL Docker 镜像快速设置流复制集群
Large factory technology implementation | industry solution series tutorials
API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)
随机推荐
ICE -- 源码分析
leetcode-396 旋转函数
pywintypes.com_error: (-2147221020, ‘无效的语法‘, None, None)
vim指定行注释和解注释
字符串最后一个单词的长度
cadence SPB17.4 - Active Class and Subclass
Codejock Suite Pro v20.3.0
携号转网最大赢家是中国电信,为何人们嫌弃中国移动和中国联通?
Import address table analysis (calculated according to the library file name: number of imported functions, function serial number and function name)
【递归之数的拆分】n分k,限定范围的拆分
Introduction to dynamic programming of leetcode learning plan day3 (198213740)
Calculate the number of occurrences of a character
utils. Deprecated in35 may be cancelled due to upgrade. What should I do
Accumulation of applet knowledge points
Advantages, disadvantages and selection of activation function
utils.DeprecatedIn35 因升级可能取消,该如何办
CVPR 2022 quality paper sharing
Date date calculation in shell script
PHP classes and objects
MySQL集群模式與應用場景