js 字符串中提取ip地址


方法1:

var reg = new RegExp(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/);
var str = 'http://172.38.172.10:8000/app/?id=stb.insight.app#module=overview.monitoring';

console.log(str.match(reg))

方法2: (js中封裝了正則方法 可以簡便使用)

var reg = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
var str = 'http://172.38.172.10:8000/app/?id=stb.insight.app#module=overview.monitoring';

console.log(str.match(reg))

補充:(一個字符串中包含多個ip)

var reg = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/g;
var str = 'http://172.38.172.10:8000/app/?id=stb.insight.app#module=overview.monitoring://172.39.172.22';

console.log(str.match(reg))

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM