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
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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "^(?P<key>[^#]\\S+) ?= ?\"(?P<value>.+)\"$"; final String string = ".encoding = \"UTF-8\"\n" + "bios.bootorder = \"hdd,cdrom\"\n" + "checkpoint.vmstate = \"\"\n" + "cleanshutdown = \"TRUE\"\n" + "config.version = \"8\"\n" + "displayname = \"generic-ubuntu1804-vmware\"\n" + "ehci.pcislotnumber = \"-1\"\n" + "ehci.present = \"FALSE\"\n" + "extendedconfigfile = \"generic-ubuntu1804-vmware.vmxf\"\n" + "floppy0.present = \"FALSE\"\n" + "guestos = \"ubuntu-64\"\n" + "guestos.detailed.data = \"bitness='64' distroName='Ubuntu' distroVersion='18.04' familyName='Linux' kernelVersion='4.15.0-76-generic' prettyName='Ubuntu 18.04.4 LTS'\"\n" + "gui.fullscreenatpoweron = \"FALSE\"\n" + "gui.viewmodeatpoweron = \"windowed\"\n" + "hgfs.linkrootshare = \"TRUE\"\n" + "hgfs.maprootshare = \"TRUE\"\n" + "ide0:0.clientdevice = \"TRUE\"\n" + "ide0:0.devicetype = \"cdrom-raw\"\n" + "ide0:0.filename = \"auto detect\"\n" + "ide0:0.present = \"TRUE\"\n" + "isolation.tools.hgfs.disable = \"FALSE\"\n" + "memsize = \"2048\"\n" + "monitor.phys_bits_used = \"42\"\n" + "msg.autoanswer = \"true\"\n" + "numa.autosize.cookie = \"20001\"\n" + "numa.autosize.vcpu.maxpervirtualnode = \"2\"\n" + "numvcpus = \"2\"\n" + "nvme0.present = \"FALSE\"\n" + "nvram = \"generic-ubuntu1804-vmware.nvram\"\n" + "parallel0.autodetect = \"FALSE\"\n" + "parallel0.bidirectional = \"\"\n" + "parallel0.filename = \"\"\n" + "parallel0.present = \"FALSE\"\n" + "parallel0.startconnected = \"FALSE\"\n" + "pcibridge0.pcislotnumber = \"17\"\n" + "pcibridge0.present = \"TRUE\"\n" + "pcibridge4.functions = \"8\"\n" + "pcibridge4.pcislotnumber = \"21\"\n" + "pcibridge4.present = \"TRUE\"\n" + "pcibridge4.virtualdev = \"pcieRootPort\"\n" + "pcibridge5.functions = \"8\"\n" + "pcibridge5.pcislotnumber = \"22\"\n" + "pcibridge5.present = \"TRUE\"\n" + "pcibridge5.virtualdev = \"pcieRootPort\"\n" + "pcibridge6.functions = \"8\"\n" + "pcibridge6.pcislotnumber = \"23\"\n" + "pcibridge6.present = \"TRUE\"\n" + "pcibridge6.virtualdev = \"pcieRootPort\"\n" + "pcibridge7.functions = \"8\"\n" + "pcibridge7.pcislotnumber = \"24\"\n" + "pcibridge7.present = \"TRUE\"\n" + "pcibridge7.virtualdev = \"pcieRootPort\"\n" + "powertype.poweroff = \"soft\"\n" + "powertype.poweron = \"soft\"\n" + "powertype.reset = \"soft\"\n" + "powertype.suspend = \"soft\"\n" + "proxyapps.publishtohost = \"FALSE\"\n" + "remotedisplay.vnc.enabled = \"FALSE\"\n" + "remotedisplay.vnc.ip = \"127.0.0.1\"\n" + "remotedisplay.vnc.port = \"5904\"\n" + "replay.filename = \"\"\n" + "replay.supported = \"FALSE\"\n" + "sata0.present = \"FALSE\"\n" + "scsi0.pcislotnumber = \"16\"\n" + "scsi0.present = \"TRUE\"\n" + "scsi0.virtualdev = \"lsilogic\"\n" + "scsi0:0.filename = \"generic-ubuntu1804-vmware.vmdk\"\n" + "scsi0:0.present = \"TRUE\"\n" + "scsi0:0.redo = \"\"\n" + "serial0.autodetect = \"FALSE\"\n" + "serial0.filename = \"\"\n" + "serial0.filetype = \"\"\n" + "serial0.pipe.endpoint = \"\"\n" + "serial0.present = \"FALSE\"\n" + "serial0.startconnected = \"FALSE\"\n" + "serial0.trynorxloss = \"\"\n" + "serial0.yieldonmsrread = \"\"\n" + "softpoweroff = \"FALSE\"\n" + "sound.autodetect = \"TRUE\"\n" + "sound.filename = \"-1\"\n" + "sound.present = \"FALSE\"\n" + "sound.startconnected = \"FALSE\"\n" + "svga.guestbackedprimaryaware = \"TRUE\"\n" + "svga.vramsize = \"134217728\"\n" + "tools.synctime = \"TRUE\"\n" + "tools.upgrade.policy = \"upgradeAtPowerCycle\"\n" + "toolsinstallmanager.updatecounter = \"1\"\n" + "usb.pcislotnumber = \"-1\"\n" + "usb.present = \"FALSE\"\n" + "uuid.action = \"create\"\n" + "uuid.bios = \"56 4d fc 04 54 ab 8e 06-3c c5 a6 4d f9 c8 bc 5a\"\n" + "uuid.location = \"56 4d fc 04 54 ab 8e 06-3c c5 a6 4d f9 c8 bc 5a\"\n" + "virtualhw.productcompatibility = \"hosted\"\n" + "virtualhw.version = \"12\"\n" + "vmci0.id = \"1861462628\"\n" + "vmci0.pcislotnumber = \"35\"\n" + "vmci0.present = \"TRUE\"\n" + "vmotion.checkpointfbsize = \"134217728\"\n" + "vmotion.checkpointsvgaprimarysize = \"134217728\"\n"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html