let reg = /https:\/\/.*\.[0-9]{1,4}(:[\w]+)?/g
这个正则匹配的结果如下
https://101.122.134.40:8860/aa.bb/aa/ee
> https://10.162.123.40:8860
https://101.122.134.40/aa.bb/aa/ee
> https://101.122.134.40
然后替换一下即可
let str = 'https://101.122.134.40:8860/aa.bb/aa/ee'
let reg = /https:\/\/.*\.[0-9]{1,4}(:[\w]+)?/g
str.replace(reg,'www.xxx.com')