regex Patterns
Regex patterns I’ve actually used. Every entry has a date and context.
2026-03-05: Multiple VLAN Alternations
Problem: Match any of several VLAN interfaces
Context: VyOS troubleshooting, checking multiple subinterfaces
The Fix:
# Match eth0.20 OR eth0.30 OR eth0.40
show interfaces | grep -E 'eth0\.(20|30|40)'
# The dot needs escaping (literal dot, not "any char")
# Parentheses group the alternation
Rule: Escape literal dots. Use (a|b|c) for alternation.
Worklog: WRKLOG-2026-03-05
2026-03-05: Bridge Member Status
Problem: Match bridge interface with specific master
Context: VyOS bridge troubleshooting
The Fix:
# Match interface with bridge master
bridge link show | grep -E "eno8.*master"
Worklog: WRKLOG-2026-03-05
2026-03-XX: IPv4 Address Extraction
Problem: Extract valid IPv4 addresses from logs
Context: Various log parsing tasks
The Fix:
# Basic IPv4 pattern
grep -oP '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' file
# More strict (0-255 per octet)
grep -oP '\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b' file
# With awk (simpler)
awk '/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/' file
Worklog: Various
2026-03-XX: MAC Address Extraction
Problem: Extract MAC addresses from various formats
Context: ISE log parsing, network troubleshooting
The Fix:
# Colon-separated (aa:bb:cc:dd:ee:ff)
grep -oiP '[0-9a-f]{2}(:[0-9a-f]{2}){5}' file
# Hyphen-separated (aa-bb-cc-dd-ee-ff)
grep -oiP '[0-9a-f]{2}(-[0-9a-f]{2}){5}' file
# Cisco format (aabb.ccdd.eeff)
grep -oiP '[0-9a-f]{4}(\.[0-9a-f]{4}){2}' file
# Any format
grep -oiP '[0-9a-f]{2}[:\-][0-9a-f]{2}[:\-][0-9a-f]{2}[:\-][0-9a-f]{2}[:\-][0-9a-f]{2}[:\-][0-9a-f]{2}' file
Worklog: Various