Networkingflags: g

TCP/UDP Port Number

Match port numbers (1–65535) following a colon, as you'd find in host:port strings.

Try it in RegexPro →

Available in

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp(":(6553[0-5]|655[0-2]\\d|65[0-4]\\d{2}|6[0-4]\\d{3}|[1-5]?\\d{1,4})\\b", "g");
const input = "http://localhost:8080";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

Pattern

regexengine-agnostic
:(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]?\d{1,4})\b   (flags: g)

Raw source: :(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]?\d{1,4})\b

How it works

The alternation enforces the 0–65535 range. Requires a leading colon for context, followed by a word boundary.

Examples

Input

http://localhost:8080

Matches

  • :8080

Input

db.example.com:5432

Matches

  • :5432

Input

api:65535

Matches

  • :65535

Common use cases

  • Extracting ports from connection strings
  • Configuration file validation
  • Firewall rule parsing
  • Service discovery tooling

Related patterns