Current location - Quotes Website - Collection of slogans - Extracting web addresses with java regular expressions
Extracting web addresses with java regular expressions
Use the splitting method of strings

var IP = ' 127. 1 1 1. 1. 1 12:8080 ';

var addr = IP . split(':')[0];

var port = IP . split(':')[ 1];

Use regularization

var reg=/(\d{ 1,3}\。 \d{ 1,3}\。 \d{ 1,3}\。 \d{ 1,3})\:(\d{ 1,4 })/;

var IP = ' 127. 1 1 1. 1. 1 12:8080 ';

var addr = ip.replace(reg,' $ 1 ');

var port = ip.replace(reg,' $ 2 ');

You can also use other string or array methods indirectly.