Regular expression for matching ports
$ npm install --save port-regex
const portRegex = require('port-regex');
portRegex().test('http://github.com:80');
//=> true
portRegex().test('127:0.0.1:3000');
//=> true
portRegex({exact: true}).test('http://github.com:80');
//=> false
portRegex({exact: true}).test(':3000');
//=> true
'http://github.com:80 127:0.0.1:3000'.match(portRegex());
//=> [':80', ':3000']
Type: boolean
Default: false
Only match an exact string. Useful with RegExp#test to check if a string is a port.
MIT © Kevin Martensson