Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
^ ([\w-_ ]+):\n\n +Type: Ethernet\n +Hardware.+\n +BSD Device Name: (.+)\n +IPv4 Addresses: (192[\.\d]+)$
/
gm

Description

Purpose:

  • Determine if your Mac is connected to an Ethernet Cable (match succeeds)
  • Returns details about connection
    • The Friendly Name (shown in Network Prefs)
    • The BSD Device Name
    • The IP address

Source Text:

Process output from this Mac shell script: system_profiler SPNetworkDataType

TAGS: @Mac @Network @Ethernet @JMichaelTX @Script

Submitted by JMichaelTX - 8 years ago