2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500
inet 192.168.1.42/24 brd 192.168.1.255 scope global eth0
Note ip is the modern Linux tool; ifconfig is legacy but still default on macOS. 'ip addr' shows addresses, 'ip route' shows the routing table, 'ip link' manages interfaces. On macOS, the primary interface is usually en0.
JS:'192.168.1.1 and 999.999.999.999'.match(/\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b/g)Py: re.findall(r'\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b', text)
Output
["192.168.1.1"] (999.999.999.999 rejected -- octets must be 0-255)
Note Each octet allows 0-255. The alternation order matters: check 25[0-5] before 2[0-4]\d before the general case. A simpler but less accurate version is \d{1,3}(\.\d{1,3}){3} which does not validate octet ranges.
Frequently asked questions
How does Bash & Linux handle ip address?
This task is covered in 2 stacks on this page: Bash & Linux, Regular Expressions. The "View & Configure Network Interfaces" snippet in Bash & Linux uses `ip addr show`.
Which command does the Bash & Linux example use?
The "View & Configure Network Interfaces" snippet uses `ip addr show`, from the Networking section of the Bash & Linux cheat sheet.
Which stacks cover "ip address" on this page?
Bash & Linux, Regular Expressions. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "View & Configure Network Interfaces": ip is the modern Linux tool; ifconfig is legacy but still default on macOS. 'ip addr' shows addresses, 'ip route' shows the routing table, 'ip link' manages interfaces. On macOS, the primary interface is usually en0.