This regex pattern matches an IP address by looking for 4 groups of 1 to 3 digits separated by periods. The \b ensures that it matches whole words only.
const regex = /\b(?:\d{1,3}\.){3}\d{1,3}\b/;
const ipAddress = '192.168.0.1';
console.log(ipAddress.match(regex));
Kopieren