js 字符串中提取ip地址

2023-06-12,,

方法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))

js 字符串中提取ip地址的相关教程结束。

《js 字符串中提取ip地址.doc》

下载本文的Word格式文档,以方便收藏与打印。