Regex for IPv4 address
/\b(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\b/g
Matches
Examples
Note
Each octet is limited to 0–255 by the alternation, which a simple \d{1,3} would not do. It still accepts leading zeros like 01.
Matches in the example
"192.168.1.1""10.0.0.255""8.8.8.8"
Token by token
\ba word boundary(?:a group, not capturing(?:a group, not capturing25the text “25”[0-5]one of: “0” to “5”|or2the character “2”[0-4]one of: “0” to “4”\da digit (0–9)|or1the character “1”\da digit (0–9)\da digit (0–9)|or[1-9]?one of: “1” to “9”, optionally\da digit (0–9))end of group\.the character “.”){3}end of group, whole group exactly 3 times(?:a group, not capturing25the text “25”[0-5]one of: “0” to “5”|or2the character “2”[0-4]one of: “0” to “4”\da digit (0–9)|or1the character “1”\da digit (0–9)\da digit (0–9)|or[1-9]?one of: “1” to “9”, optionally\da digit (0–9))end of group\ba word boundary
Other patterns
- Email address
- URL
- IPv4 address
- UUID
- Hex color
- Date (YYYY-MM-DD)
- Time (24-hour)
- US phone number
- Phone number (E.164)
- US ZIP code
- Credit card number
- URL slug
- Username
- Strong password
- HTML tag
- Semantic version
- MAC address
- JSON Web Token
- Hashtag
- @mention
- Number
- Leading and trailing whitespace
- Repeated word
- Blank lines
- Markdown link
- Quoted string
- Domain name
- File extension
- Base64
- Trailing comma