Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/NIC 1 Rule\(0\):.*?ip = ([\d.]{7,15}).*?port = (\d{1,5})/m'; $str = 'Name: MEmu Groups: / Guest OS: Other Linux (32-bit) UUID: 20201029-aaaa-aaaa-aaaa-000000000000 Config file: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu\\MEmu.memu Snapshot folder: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu\\Snapshots Log folder: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu\\Logs Hardware UUID: 20201029-aaaa-aaaa-aaaa-000000000000 Memory size: 512MB Page Fusion: off VRAM size: 12MB CPU exec cap: 100% HPET: off Chipset: piix3 Firmware: BIOS Number of CPUs: 1 PAE: on Long Mode: on Triple Fault Reset: off APIC: on X2APIC: off CPUID Portability Level: 0 CPUID overrides: None Boot menu mode: disabled Boot Device (1): HardDisk Boot Device (2): Not Assigned Boot Device (3): Not Assigned Boot Device (4): Not Assigned ACPI: on IOAPIC: on BIOS APIC mode: APIC Time offset: 0ms RTC: UTC Hardw. virt.ext: on Nested Paging: on Large Pages: on VT-x VPID: on VT-x unr. exec.: on Paravirt. Provider: Legacy Effective Paravirt. Provider: None State: running (since 2020-11-15T14:31:01.762000000) Monitor count: 1 3D Acceleration: off 2D Video Acceleration: off Teleporter Enabled: off Teleporter Port: 0 Teleporter Address: Teleporter Password: Tracing Enabled: off Allow Tracing to Access VM: off Tracing Configuration: Autostart Enabled: off Autostart Delay: 0 Default Frontend: Storage Controller Name (0): IDE Storage Controller Type (0): PIIX4 Storage Controller Instance Number (0): 0 Storage Controller Max Port Count (0): 2 Storage Controller Port Count (0): 2 Storage Controller Bootable (0): on IDE (0, 0): C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu\\MEmu44-20180125000000FF-disk1.vmdk (UUID: 3c18861c-afbc-4dc5-a282-9e28e6d979d9) IDE (0, 1): C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu\\MEmu44-20180125000000FF-disk2.vmdk (UUID: 20201029-cccc-cccc-cccc-000000000000) IDE (1, 0): C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu\\MEmu44-20180125000000FF-disk3.vmdk (UUID: 20201029-dddd-dddd-dddd-000000000000) NIC 1: MAC: 08002709FE9E, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: virtio, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none NIC 1 Settings: MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64) NIC 1 Rule(0): name = ADB, protocol = tcp, host ip = 127.0.0.1, host port = 21503, guest ip = 10.0.2.15, guest port = 5555 NIC 1 Rule(1): name = MVD, protocol = tcp, host ip = 127.0.0.1, host port = 21501, guest ip = 10.0.2.15, guest port = 21501 NIC 2: MAC: 0800279FCBC1, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: virtio, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none NIC 2 Settings: MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64) NIC 3: disabled NIC 4: disabled NIC 5: disabled NIC 6: disabled NIC 7: disabled NIC 8: disabled Pointing Device: USB Tablet Keyboard Device: PS/2 Keyboard UART 1: disabled UART 2: disabled UART 3: disabled UART 4: disabled LPT 1: disabled LPT 2: disabled Audio: enabled (Driver: Null, Controller: AC97, Codec: STAC9700) Clipboard Mode: disabled Drag and drop Mode: disabled Session name: headless VRDE: disabled USB: enabled EHCI: disabled XHCI: disabled USB Device Filters: <none> Bandwidth groups: <none> Shared folders: Name: \'music\', Host path: \'C:\\Users\\яЕПЦЕИ\\Music\\MEmu Music\' (machine mapping), writable Name: \'movie\', Host path: \'C:\\Users\\яЕПЦЕИ\\Videos\\MEmu Video\' (machine mapping), writable Name: \'picture\', Host path: \'C:\\Users\\яЕПЦЕИ\\Pictures\\MEmu Photo\' (machine mapping), writable Name: \'download\', Host path: \'C:\\Users\\яЕПЦЕИ\\Downloads\\MEmu Download\' (machine mapping), writable Video capturing: not active Capture screens: 0 Capture file: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu\\MEmu.webm Capture dimensions: 1024x768 Capture rate: 512 kbps Capture FPS: 25 Guest: Configured memory balloon size: 0 MB Name: MEmu_1 Groups: / Guest OS: Other Linux (32-bit) UUID: 20201112-aaaa-aaaa-aaaa-000000000001 Config file: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_1\\MEmu_1.memu Snapshot folder: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_1\\Snapshots Log folder: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_1\\Logs Hardware UUID: 20201112-aaaa-aaaa-aaaa-000000000001 Memory size: 512MB Page Fusion: off VRAM size: 12MB CPU exec cap: 100% HPET: off Chipset: piix3 Firmware: BIOS Number of CPUs: 1 PAE: on Long Mode: on Triple Fault Reset: off APIC: on X2APIC: off CPUID Portability Level: 0 CPUID overrides: None Boot menu mode: disabled Boot Device (1): HardDisk Boot Device (2): Not Assigned Boot Device (3): Not Assigned Boot Device (4): Not Assigned ACPI: on IOAPIC: on BIOS APIC mode: APIC Time offset: 0ms RTC: UTC Hardw. virt.ext: on Nested Paging: on Large Pages: on VT-x VPID: on VT-x unr. exec.: on Paravirt. Provider: Legacy Effective Paravirt. Provider: None State: running (since 2020-11-15T14:31:02.670000000) Monitor count: 1 3D Acceleration: off 2D Video Acceleration: off Teleporter Enabled: off Teleporter Port: 0 Teleporter Address: Teleporter Password: Tracing Enabled: off Allow Tracing to Access VM: off Tracing Configuration: Autostart Enabled: off Autostart Delay: 0 Default Frontend: Storage Controller Name (0): IDE Storage Controller Type (0): PIIX4 Storage Controller Instance Number (0): 0 Storage Controller Max Port Count (0): 2 Storage Controller Port Count (0): 2 Storage Controller Bootable (0): on IDE (0, 0): C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_1\\MEmu44-20180125000000FF-disk1.vmdk (UUID: 20201112-bbbb-bbbb-bbbb-000000000001) IDE (0, 1): C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_1\\MEmu44-20180125000000FF-disk2.vmdk (UUID: 20201112-cccc-cccc-cccc-000000000001) IDE (1, 0): C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_1\\MEmu44-20180125000000FF-disk3.vmdk (UUID: 20201112-dddd-dddd-dddd-000000000001) NIC 1: MAC: 360828098894, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: virtio, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none NIC 1 Settings: MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64) NIC 1 Rule(0): name = ADB, protocol = tcp, host ip = 127.0.0.1, host port = 21513, guest ip = 10.0.2.15, guest port = 5555 NIC 1 Rule(1): name = MVD, protocol = tcp, host ip = 127.0.0.1, host port = 21511, guest ip = 10.0.2.15, guest port = 21501 NIC 2: MAC: A8F6B0302130, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: virtio, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none NIC 2 Settings: MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64) NIC 3: disabled NIC 4: disabled NIC 5: disabled NIC 6: disabled NIC 7: disabled NIC 8: disabled Pointing Device: USB Tablet Keyboard Device: PS/2 Keyboard UART 1: disabled UART 2: disabled UART 3: disabled UART 4: disabled LPT 1: disabled LPT 2: disabled Audio: enabled (Driver: Null, Controller: AC97, Codec: STAC9700) Clipboard Mode: disabled Drag and drop Mode: disabled Session name: headless VRDE: disabled USB: enabled EHCI: disabled XHCI: disabled USB Device Filters: <none> Bandwidth groups: <none> Shared folders: Name: \'music\', Host path: \'C:\\Users\\яЕПЦЕИ\\Music\\MEmu Music\' (machine mapping), writable Name: \'movie\', Host path: \'C:\\Users\\яЕПЦЕИ\\Videos\\MEmu Video\' (machine mapping), writable Name: \'picture\', Host path: \'C:\\Users\\яЕПЦЕИ\\Pictures\\MEmu Photo\' (machine mapping), writable Name: \'download\', Host path: \'C:\\Users\\яЕПЦЕИ\\Downloads\\MEmu Download\' (machine mapping), writable Video capturing: not active Capture screens: 0 Capture file: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_1\\MEmu_1.webm Capture dimensions: 1024x768 Capture rate: 512 kbps Capture FPS: 25 Guest: Configured memory balloon size: 0 MB Name: MEmu_2 Groups: / Guest OS: Other Linux (32-bit) UUID: 20201112-aaaa-aaaa-aaaa-000000000002 Config file: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_2\\MEmu_2.memu Snapshot folder: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_2\\Snapshots Log folder: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_2\\Logs Hardware UUID: 20201112-aaaa-aaaa-aaaa-000000000002 Memory size: 512MB Page Fusion: off VRAM size: 12MB CPU exec cap: 100% HPET: off Chipset: piix3 Firmware: BIOS Number of CPUs: 1 PAE: on Long Mode: on Triple Fault Reset: off APIC: on X2APIC: off CPUID Portability Level: 0 CPUID overrides: None Boot menu mode: disabled Boot Device (1): HardDisk Boot Device (2): Not Assigned Boot Device (3): Not Assigned Boot Device (4): Not Assigned ACPI: on IOAPIC: on BIOS APIC mode: APIC Time offset: 0ms RTC: UTC Hardw. virt.ext: on Nested Paging: on Large Pages: on VT-x VPID: on VT-x unr. exec.: on Paravirt. Provider: Legacy Effective Paravirt. Provider: None State: running (since 2020-11-15T14:31:04.475000000) Monitor count: 1 3D Acceleration: off 2D Video Acceleration: off Teleporter Enabled: off Teleporter Port: 0 Teleporter Address: Teleporter Password: Tracing Enabled: off Allow Tracing to Access VM: off Tracing Configuration: Autostart Enabled: off Autostart Delay: 0 Default Frontend: Storage Controller Name (0): IDE Storage Controller Type (0): PIIX4 Storage Controller Instance Number (0): 0 Storage Controller Max Port Count (0): 2 Storage Controller Port Count (0): 2 Storage Controller Bootable (0): on IDE (0, 0): C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_2\\MEmu44-20180125000000FF-disk1.vmdk (UUID: 20201112-bbbb-bbbb-bbbb-000000000002) IDE (0, 1): C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_2\\MEmu44-20180125000000FF-disk2.vmdk (UUID: 20201112-cccc-cccc-cccc-000000000002) IDE (1, 0): C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_2\\MEmu44-20180125000000FF-disk3.vmdk (UUID: 20201112-dddd-dddd-dddd-000000000002) NIC 1: MAC: 445929981808, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: virtio, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none NIC 1 Settings: MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64) NIC 1 Rule(0): name = ADB, protocol = tcp, host ip = 127.0.0.1, host port = 21523, guest ip = 10.0.2.15, guest port = 5555 NIC 1 Rule(1): name = MVD, protocol = tcp, host ip = 127.0.0.1, host port = 21521, guest ip = 10.0.2.15, guest port = 21501 NIC 2: MAC: A8F5E2EBF25D, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: virtio, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none NIC 2 Settings: MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64) NIC 3: disabled NIC 4: disabled NIC 5: disabled NIC 6: disabled NIC 7: disabled NIC 8: disabled Pointing Device: USB Tablet Keyboard Device: PS/2 Keyboard UART 1: disabled UART 2: disabled UART 3: disabled UART 4: disabled LPT 1: disabled LPT 2: disabled Audio: enabled (Driver: Null, Controller: AC97, Codec: STAC9700) Clipboard Mode: disabled Drag and drop Mode: disabled Session name: headless VRDE: disabled USB: enabled EHCI: disabled XHCI: disabled USB Device Filters: <none> Bandwidth groups: <none> Shared folders: Name: \'music\', Host path: \'C:\\Users\\яЕПЦЕИ\\Music\\MEmu Music\' (machine mapping), writable Name: \'movie\', Host path: \'C:\\Users\\яЕПЦЕИ\\Videos\\MEmu Video\' (machine mapping), writable Name: \'picture\', Host path: \'C:\\Users\\яЕПЦЕИ\\Pictures\\MEmu Photo\' (machine mapping), writable Name: \'download\', Host path: \'C:\\Users\\яЕПЦЕИ\\Downloads\\MEmu Download\' (machine mapping), writable Video capturing: not active Capture screens: 0 Capture file: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_2\\MEmu_2.webm Capture dimensions: 1024x768 Capture rate: 512 kbps Capture FPS: 25 Guest: Configured memory balloon size: 0 MB Name: MEmu_3 Groups: / Guest OS: Other Linux (32-bit) UUID: 20201112-aaaa-aaaa-aaaa-000000000003 Config file: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_3\\MEmu_3.memu Snapshot folder: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_3\\Snapshots Log folder: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_3\\Logs Hardware UUID: 20201112-aaaa-aaaa-aaaa-000000000003 Memory size: 512MB Page Fusion: off VRAM size: 12MB CPU exec cap: 100% HPET: off Chipset: piix3 Firmware: BIOS Number of CPUs: 1 PAE: on Long Mode: on Triple Fault Reset: off APIC: on X2APIC: off CPUID Portability Level: 0 CPUID overrides: None Boot menu mode: disabled Boot Device (1): HardDisk Boot Device (2): Not Assigned Boot Device (3): Not Assigned Boot Device (4): Not Assigned ACPI: on IOAPIC: on BIOS APIC mode: APIC Time offset: 0ms RTC: UTC Hardw. virt.ext: on Nested Paging: on Large Pages: on VT-x VPID: on VT-x unr. exec.: on Paravirt. Provider: Legacy Effective Paravirt. Provider: None State: running (since 2020-11-15T14:31:04.475000000) Monitor count: 1 3D Acceleration: off 2D Video Acceleration: off Teleporter Enabled: off Teleporter Port: 0 Teleporter Address: Teleporter Password: Tracing Enabled: off Allow Tracing to Access VM: off Tracing Configuration: Autostart Enabled: off Autostart Delay: 0 Default Frontend: Storage Controller Name (0): IDE Storage Controller Type (0): PIIX4 Storage Controller Instance Number (0): 0 Storage Controller Max Port Count (0): 2 Storage Controller Port Count (0): 2 Storage Controller Bootable (0): on IDE (0, 0): C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_3\\MEmu44-20180125000000FF-disk1.vmdk (UUID: 20201112-bbbb-bbbb-bbbb-000000000003) IDE (0, 1): C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_3\\MEmu44-20180125000000FF-disk2.vmdk (UUID: 20201112-cccc-cccc-cccc-000000000003) IDE (1, 0): C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_3\\MEmu44-20180125000000FF-disk3.vmdk (UUID: 20201112-dddd-dddd-dddd-000000000003) NIC 1: MAC: 366807061729, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: virtio, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none NIC 1 Settings: MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64) NIC 1 Rule(0): name = ADB, protocol = tcp, host ip = 127.0.0.1, host port = 21533, guest ip = 10.0.2.15, guest port = 5555 NIC 1 Rule(1): name = MVD, protocol = tcp, host ip = 127.0.0.1, host port = 21531, guest ip = 10.0.2.15, guest port = 21501 NIC 2: MAC: 70A31C00CB3E, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: virtio, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none NIC 2 Settings: MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64) NIC 3: disabled NIC 4: disabled NIC 5: disabled NIC 6: disabled NIC 7: disabled NIC 8: disabled Pointing Device: USB Tablet Keyboard Device: PS/2 Keyboard UART 1: disabled UART 2: disabled UART 3: disabled UART 4: disabled LPT 1: disabled LPT 2: disabled Audio: enabled (Driver: Null, Controller: AC97, Codec: STAC9700) Clipboard Mode: disabled Drag and drop Mode: disabled Session name: headless VRDE: disabled USB: enabled EHCI: disabled XHCI: disabled USB Device Filters: <none> Bandwidth groups: <none> Shared folders: Name: \'music\', Host path: \'C:\\Users\\яЕПЦЕИ\\Music\\MEmu Music\' (machine mapping), writable Name: \'movie\', Host path: \'C:\\Users\\яЕПЦЕИ\\Videos\\MEmu Video\' (machine mapping), writable Name: \'picture\', Host path: \'C:\\Users\\яЕПЦЕИ\\Pictures\\MEmu Photo\' (machine mapping), writable Name: \'download\', Host path: \'C:\\Users\\яЕПЦЕИ\\Downloads\\MEmu Download\' (machine mapping), writable Video capturing: not active Capture screens: 0 Capture file: C:\\Program Files\\Microvirt\\MEmu\\MemuHyperv VMs\\MEmu_3\\MEmu_3.webm Capture dimensions: 1024x768 Capture rate: 512 kbps Capture FPS: 25 Guest: Configured memory balloon size: 0 MB'; 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