当前位置:网站首页>JS regular determines whether the port path of the domain name or IP is correct
JS regular determines whether the port path of the domain name or IP is correct
2022-04-23 15:47:00 【Victorian youth-】
adopt js Regular to judge ip Port path http://127.0.0.1:3000/list perhaps https://www.baidu.com:8080/list Whether it is right
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
Verified integrity url, The following method can be used to extract ip、 port . route
// obtain ip Address 、 port 、 Lu Jin
getUrlComponent (url) {
let res = {
}
if (url.indexOf('//') !== -1 || url.indexOf(':') !== -1 || url.indexOf('.') !== -1) {
// Don't intercept 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
}
版权声明
本文为[Victorian youth-]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231547082639.html
边栏推荐
- WPS品牌再升级专注国内,另两款国产软件低调出国门,却遭禁令
- Fastjon2他来了,性能显著提升,还能再战十年
- MySQL optimistic lock to solve concurrency conflict
- Basic greedy summary
- 为啥禁用外键约束
- 导入地址表分析(根据库文件名求出:导入函数数量、函数序号、函数名称)
- 开源项目推荐:3D点云处理软件ParaView,基于Qt和VTK
- 【AI周报】英伟达用AI设计芯片;不完美的Transformer要克服自注意力的理论缺陷
- Codejock Suite Pro v20. three
- Spark 算子之coalesce与repartition
猜你喜欢
Spark 算子之groupBy使用
API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)
How can poor areas without networks have money to build networks?
Why disable foreign key constraints
WPS brand was upgraded to focus on China. The other two domestic software were banned from going abroad with a low profile
Use bitnami PostgreSQL docker image to quickly set up stream replication clusters
Multi level cache usage
IronPDF for .NET 2022.4.5455
基于 TiDB 的 Apache APISIX 高可用配置中心的最佳实践
移动金融(自用)
随机推荐
What if the package cannot be found
Go语言切片,范围,集合
Load Balancer
Calculate the number of occurrences of a character
PHP classes and objects
C, calculation method and source program of bell number
现在做自媒体能赚钱吗?看完这篇文章你就明白了
APISIX jwt-auth 插件存在错误响应中泄露信息的风险公告(CVE-2022-29266)
The length of the last word of the string
Modèle de Cluster MySQL et scénario d'application
开源项目推荐:3D点云处理软件ParaView,基于Qt和VTK
MySQL集群模式与应用场景
Mobile finance (for personal use)
How do you think the fund is REITs? Is it safe to buy the fund through the bank
MySQL optimistic lock to solve concurrency conflict
utils. Deprecated in35 may be cancelled due to upgrade. What should I do
Treatment of idempotency
Go language, array, pointer, structure
Spark 算子之coalesce与repartition
fatal error: torch/extension. h: No such file or directory