Regex for IPv4 addresses

Example pattern below—edit it or paste your own. All processing runs in your browser. For Python’s re module, switch flavor in the tool.

Flavor

Standard `RegExp` for explanation and preview.

g i m s u y d v (JavaScript)
Gateways 192.168.0.1 and 10.0.0.255 should match.

Plain-English explanation

Flavor: JavaScript RegExp

Flags: g (find all matches)

a word boundary Then Match (non-capturing): Match one of: (1) Match the character "2". Then Match the character "5". Then Match one character from: characters from the character "0" to the character "5". OR (2) Match the character "2". Then Match one character from: characters from the character "0" to the character "4". Then Match digit character (0–9). OR (3) Match one character from: the character "0", the character "1", optional. Then Match digit character (0–9), repeated between 1 and 2 times. Then Match the character ".", repeated exactly 3 times. Then Match one of: (1) Match the character "2". Then Match the character "5". Then Match one character from: characters from the character "0" to the character "5". OR (2) Match the character "2". Then Match one character from: characters from the character "0" to the character "4". Then Match digit character (0–9). OR (3) Match one character from: the character "0", the character "1", optional. Then Match digit character (0–9), repeated between 1 and 2 times. Then a word boundary

More examples

Back to RegExplain