Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression
Processing...

Test String

Code Generator

Generated Code

$re = '/^ ([\w -_ ]+):\n\n +Type: Ethernet\n +Hardware.+\n +BSD Device Name: (.+)\n +IPv4 Addresses: (192[\.\d]+)$/m'; $str = 'Network: USB 10/100/1000 LAN 2: Type: Ethernet Hardware: Ethernet BSD Device Name: en6 IPv4 Addresses: 192.168.136.251 IPv4: AdditionalRoutes: DestinationAddress: 192.168.136.251 SubnetMask: 255.255.255.255 DestinationAddress: 169.254.0.0 SubnetMask: 255.255.0.0 Addresses: 192.168.136.251 ARPResolvedHardwareAddress: f6:92:bf:88:c8:2e ARPResolvedIPAddress: 192.168.136.1 Configuration Method: INFORM ConfirmedInterfaceName: en6 Interface Name: en6 Network Signature: IPv4.Router=192.168.136.1;IPv4.RouterHardwareAddress=f6:92:bf:88:c8:2e Router: 192.168.136.1 Subnet Masks: 255.255.255.255 IPv6: Addresses: 2601:283:4200:d0a:42f:af72:ae41:3c8f, 2601:283:4200:d0a:bdb9:1223:3c59:f741, fd7b:2874:64bb:10:c0c:5dc1:be14:6d7d, fd7b:2874:64bb:10:a583:5011:61f6:cb0d Configuration Method: Automatic ConfirmedInterfaceName: en6 Interface Name: en6 Network Signature: IPv6.Prefix=2601:283:4200:d0a::/64;IPv6.RouterHardwareAddress=f6:92:bf:88:c8:2e Prefix Length: 64, 64, 64, 64 Router: fe80::f492:bfff:fe88:c82e DNS: Server Addresses: 192.168.136.1, fd7b:2874:64bb:10::1 DHCP Server Responses: Domain Name Servers: 192.168.136.1 DHCP Message Type: 0x05 Routers: 192.168.136.1 Server Identifier: 192.168.136.1 Ethernet: MAC Address: 00:e0:4c:68:0f:96 Media Options: Full Duplex Media Subtype: 1000baseT Proxies: Exceptions List: *.local, 169.254/16 FTP Passive Mode: Yes Service Order: 0 USB 10/100/1000 LAN: Type: Ethernet Hardware: Ethernet BSD Device Name: en7 IPv4: Configuration Method: DHCP IPv6: Configuration Method: Automatic Proxies: Exceptions List: *.local, 169.254/16 FTP Passive Mode: Yes Service Order: 1 USB Ethernet: Type: Ethernet Hardware: Ethernet BSD Device Name: en7 IPv4 Addresses: 10.10.10.6 IPv4: Addresses: 10.10.10.6 Configuration Method: Manual Subnet Masks: 255.255.0.0 IPv6: Configuration Method: Automatic DNS: Server Addresses: 1.1.1.1, 1.0.0.1, 2606:4700:4700::1111, 2606:4700:4700::1111 Proxies: Exceptions List: *.local, 169.254/16 FTP Passive Mode: Yes Service Order: 2 USB 10/100/1000 LAN 3: Type: Ethernet Hardware: Ethernet BSD Device Name: en11 IPv4: Configuration Method: DHCP IPv6: Configuration Method: Automatic Proxies: Exceptions List: *.local, 169.254/16 FTP Passive Mode: Yes Service Order: 3 Wi-Fi: Type: AirPort Hardware: AirPort BSD Device Name: en0 IPv4 Addresses: 192.168.136.184 IPv4: AdditionalRoutes: DestinationAddress: 192.168.136.184 SubnetMask: 255.255.255.255 DestinationAddress: 169.254.0.0 SubnetMask: 255.255.0.0 Addresses: 192.168.136.184 ARPResolvedHardwareAddress: f6:92:bf:88:c8:2e ARPResolvedIPAddress: 192.168.136.1 Configuration Method: DHCP ConfirmedInterfaceName: en0 Interface Name: en0 Network Signature: IPv4.Router=192.168.136.1;IPv4.RouterHardwareAddress=f6:92:bf:88:c8:2e Router: 192.168.136.1 Subnet Masks: 255.255.255.0 IPv6: Addresses: 2601:283:4200:d0a:1849:f70b:a649:aaa1, 2601:283:4200:d0a:7088:d9:fe7e:80e8, fd7b:2874:64bb:10:2d:2f19:470f:32d1, fd7b:2874:64bb:10:a12f:2f04:f8c:1cbb Configuration Method: Automatic ConfirmedInterfaceName: en0 Interface Name: en0 Network Signature: IPv6.Prefix=2601:283:4200:d0a::/64;IPv6.RouterHardwareAddress=f6:92:bf:88:c8:2e Prefix Length: 64, 64, 64, 64 Router: fe80::f492:bfff:fe88:c82e DNS: Server Addresses: 192.168.136.1, fd7b:2874:64bb:10::1 DHCP Server Responses: Domain Name Servers: 192.168.136.1 Lease Duration (seconds): 0 DHCP Message Type: 0x05 Routers: 192.168.136.1 Server Identifier: 192.168.136.1 Subnet Mask: 255.255.255.0 Ethernet: MAC Address: f8:ff:c2:67:29:32 Media Options: Media Subtype: Auto Select Proxies: Exceptions List: *.local, 169.254/16 FTP Passive Mode: Yes Sleep Proxies: 1 m&m tv: Marginal Power: 60 Metric: 703560 Portability: 35 Total Power: 63 Type: 70 1 workout room: Marginal Power: 60 Metric: 703560 Portability: 35 Total Power: 63 Type: 70 Service Order: 4 SparkFun Pro Micro: Type: PPP (PPPSerial) Hardware: Modem BSD Device Name: usbmodem14131 IPv4: Configuration Method: PPP IPv6: Configuration Method: Automatic Proxies: FTP Passive Mode: Yes Service Order: 5 Display Ethernet: Type: Ethernet Hardware: Ethernet BSD Device Name: en9 IPv4 Addresses: 10.10.10.1 IPv4: Addresses: 10.10.10.1 Configuration Method: Manual Subnet Masks: 255.255.0.0 IPv6: Configuration Method: Automatic Ethernet: MAC Address: 0c:4d:e9:ae:d3:b3 Media Options: Media Subtype: none Proxies: Exceptions List: *.local, 169.254/16 FTP Passive Mode: Yes Service Order: 6 Thunderbolt Ethernet: Type: Ethernet Hardware: Ethernet BSD Device Name: en12 IPv4 Addresses: 10.10.10.3 IPv4: Addresses: 10.10.10.3 Configuration Method: Manual Subnet Masks: 255.255.255.0 IPv6: Configuration Method: Automatic Proxies: Exceptions List: *.local, 169.254/16 FTP Passive Mode: Yes Service Order: 7 Thunderbolt Ethernet Slot 1, Port 1: Type: Ethernet Hardware: Ethernet BSD Device Name: en10 IPv4: Configuration Method: DHCP IPv6: Configuration Method: Automatic Ethernet: MAC Address: 64:4b:f0:19:ac:9c Media Options: Media Subtype: Auto Select Proxies: Exceptions List: *.local, 169.254/16 FTP Passive Mode: Yes Service Order: 8 Display FireWire: Type: FireWire Hardware: FireWire BSD Device Name: fw0 IPv4: Configuration Method: DHCP IPv6: Configuration Method: Automatic Ethernet: MAC Address: 00:0a:27:02:00:5d:2a:82 Media Options: Full Duplex Media Subtype: Auto Select Proxies: Exceptions List: *.local, 169.254/16 FTP Passive Mode: Yes Service Order: 9 Bluetooth PAN 2: Type: Ethernet Hardware: Ethernet BSD Device Name: en8 IPv4: Configuration Method: DHCP IPv6: Configuration Method: Automatic Proxies: Exceptions List: *.local, 169.254/16 FTP Passive Mode: Yes Service Order: 10 Thunderbolt Bridge: Type: Ethernet Hardware: Ethernet BSD Device Name: bridge0 IPv4 Addresses: 10.10.10.2 IPv4: Addresses: 10.10.10.2 Configuration Method: Manual Subnet Masks: 255.0.0.0 IPv6: Configuration Method: Link Local Proxies: Exceptions List: *.local, 169.254/16 FTP Passive Mode: Yes Service Order: 11 Thunderbolt FireWire: Type: FireWire Hardware: FireWire BSD Device Name: fw1 IPv4: Configuration Method: DHCP IPv6: Configuration Method: Automatic Proxies: Exceptions List: *.local, 169.254/16 FTP Passive Mode: Yes Service Order: 12 Thunderbolt FireWire 2: Type: FireWire Hardware: FireWire BSD Device Name: fw2 IPv4: Configuration Method: DHCP IPv6: Configuration Method: Automatic Proxies: Exceptions List: *.local, 169.254/16 FTP Passive Mode: Yes Service Order: 13 Thunderbolt Bridge 2: Type: Ethernet Hardware: Ethernet BSD Device Name: bridge0 IPv4: Configuration Method: DHCP IPv6: Configuration Method: Automatic Proxies: Exceptions List: *.local, 169.254/16 FTP Passive Mode: Yes Service Order: 14 '; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php