Regular Expressions 101

Community Patterns

Regex to group output of $(ip addr) interface

1

Regular Expression
Python

r"
\d: ([\w@]+): <(.+)> mtu (\d+) qdisc (\w+) qlen (\d+)\n[ ]+(\w+\/\w+) ([\d:\w.]+) brd ([\d:\w.]+)\n?(?:(?: )+inet6? ([\d.:\/]+) (?:brd ([\d:\w.]+) )?scope (\w+) (?:\w+)?\n(?: )+valid_lft (\w+) preferred_lft (\w+))?
"
gm

Description

For this task, I did not need inet6 (IPv6 stuff), so I left it out. The regex in its current state does not allow for that to be included without manually adding the entire second part

Submitted by anonymous - 6 years ago