当前位置:网站首页>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
边栏推荐
猜你喜欢

基于 TiDB 的 Apache APISIX 高可用配置中心的最佳实践

幂等性的处理

Spark 算子之交集、并集、差集

MetaLife与ESTV建立战略合作伙伴关系并任命其首席执行官Eric Yoon为顾问

王启亨谈Web3.0与价值互联网“通证交换”

C, calculation method and source program of bell number

JVM-第2章-类加载子系统(Class Loader Subsystem)

MySQL Cluster Mode and application scenario

Codejock Suite Pro v20.3.0

【开源工具分享】单片机调试助手(示波/改值/日志) - LinkScope
随机推荐
KNN, kmeans and GMM
cadence SPB17. 4 - Active Class and Subclass
Why is IP direct connection prohibited in large-scale Internet
Spark 算子之coalesce与repartition
The El tree implementation only displays a certain level of check boxes and selects radio
Fastjon2他来了,性能显著提升,还能再战十年
Basic concepts of website construction and management
C language --- advanced pointer
[backtrader source code analysis 18] Yahoo Py code comments and analysis (boring, interested in the code, you can refer to)
Cap theorem
山寨版归并【上】
MySQL optimistic lock to solve concurrency conflict
c语言---字符串+内存函数
pywintypes.com_error: (-2147221020, ‘无效的语法‘, None, None)
String sorting
Extract non duplicate integers
携号转网最大赢家是中国电信,为何人们嫌弃中国移动和中国联通?
Go language slice, range, set
Demonstration meeting on startup and implementation scheme of swarm intelligence autonomous operation smart farm project
Spark 算子之交集、并集、差集