Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "\\s*([\\w ]+):\\s*(\"(?:\\\\\"[^,]|\\\\\"|\\\\|[^\\\"])+\"|[^,]*)(?:,|$)"; final String string = "1girl\n" + "Negative prompt: art by xynon-bad-11k-2\n" + "Steps: 24, Sampler: DPM++ 2M Karras, CFG scale: 7, Seed: 425230810, Size: 640x640, Model hash: b836e500e5, Model: silica_base2-rebasin, Denoising strength: 0.5, CFG Rescale phi: 0, Hires upscale: 1.6, Hires steps: 14, Hires upscaler: 4x_DPED, TI hashes: \"xynon-bad-11k-2: 796c84e2a27c\", ComfyUI Workflows: \"{\\\"postprocess_latent\\\": {\\\"last_node_id\\\": 22, \\\"last_link_id\\\": 330, \\\"nodes\\\": [{\\\"id\\\": 4, \\\"type\\\": \\\"ToWebui\\\", \\\"pos\\\": [937, 80], \\\"size\\\": [240, 60], \\\"flags\\\": {\\\"collapsed\\\": true}, \\\"order\\\": 10, \\\"mode\\\": 0, \\\"inputs\\\": [{\\\"name\\\": \\\"LATENT\\\", \\\"type\\\": \\\"LATENT\\\", \\\"link\\\": 85}], \\\"properties\\\": {\\\"Node name for S&R\\\": \\\"ToWebui\\\"}}, {\\\"id\\\": 3, \\\"type\\\": \\\"FromWebui\\\", \\\"pos\\\": [-123, 110], \\\"size\\\": [240, 60], \\\"flags\\\": {\\\"collapsed\\\": true}, \\\"order\\\": 0, \\\"mode\\\": 0, \\\"outputs\\\": [{\\\"name\\\": \\\"LATENT\\\", \\\"type\\\": \\\"LATENT\\\", \\\"links\\\": [18, 20, 108], \\\"shape\\\": 3, \\\"slot_index\\\": 0}], \\\"properties\\\": {\\\"Node name for S&R\\\": \\\"FromWebui\\\"}, \\\"widgets_values\\\": [\\\"0.80553704976941531692335377331\\\"]}, {\\\"id\\\": 13, \\\"type\\\": \\\"VAEDecode\\\", \\\"pos\\\": [2344, 364], \\\"size\\\": {\\\"0\\\": 210, \\\"1\\\": 46}, \\\"flags\\\": {\\\"collapsed\\\": true}, \\\"order\\\": 9, \\\"mode\\\": 0, \\\"inputs\\\": [{\\\"name\\\": \\\"samples\\\", \\\"type\\\": \\\"LATENT\\\", \\\"link\\\": 35, \\\"slot_index\\\": 0}, {\\\"name\\\": \\\"vae\\\", \\\"type\\\": \\\"VAE\\\", \\\"link\\\": 326}], \\\"outputs\\\": [{\\\"name\\\": \\\"IMAGE\\\", \\\"type\\\": \\\"IMAGE\\\", \\\"links\\\": [17], \\\"shape\\\": 3, \\\"slot_index\\\": 0}], \\\"properties\\\": {\\\"Node name for S&R\\\": \\\"VAEDecode\\\"}}, {\\\"id\\\": 12, \\\"type\\\": \\\"VAEDecode\\\", \\\"pos\\\": [1798, 365], \\\"size\\\": {\\\"0\\\": 210, \\\"1\\\": 46}, \\\"flags\\\": {\\\"collapsed\\\": true}, \\\"order\\\": 5, \\\"mode\\\": 0, \\\"inputs\\\": [{\\\"name\\\": \\\"samples\\\", \\\"type\\\": \\\"LATENT\\\", \\\"link\\\": 13, \\\"slot_index\\\": 0}, {\\\"name\\\": \\\"vae\\\", \\\"type\\\": \\\"VAE\\\", \\\"link\\\": 325}], \\\"outputs\\\": [{\\\"name\\\": \\\"IMAGE\\\", \\\"type\\\": \\\"IMAGE\\\", \\\"links\\\": [12], \\\"shape\\\": 3, \\\"slot_index\\\": 0}], \\\"properties\\\": {\\\"Node name for S&R\\\": \\\"VAEDecode\\\"}}, {\\\"id\\\": 16, \\\"type\\\": \\\"VAEDecode\\\", \\\"pos\\\": [1252, 361], \\\"size\\\": {\\\"0\\\": 210, \\\"1\\\": 46}, \\\"flags\\\": {\\\"collapsed\\\": true}, \\\"order\\\": 2, \\\"mode\\\": 0, \\\"inputs\\\": [{\\\"name\\\": \\\"samples\\\", \\\"type\\\": \\\"LATENT\\\", \\\"link\\\": 20, \\\"slot_index\\\": 0}, {\\\"name\\\": \\\"vae\\\", \\\"type\\\": \\\"VAE\\\", \\\"link\\\": 324, \\\"slot_index\\\": 1}], \\\"outputs\\\": [{\\\"name\\\": \\\"IMAGE\\\", \\\"type\\\": \\\"IMAGE\\\", \\\"links\\\": [19], \\\"shape\\\": 3, \\\"slot_index\\\": 0}], \\\"properties\\\": {\\\"Node name for S&R\\\": \\\"VAEDecode\\\"}}, {\\\"id\\\": 6, \\\"type\\\": \\\"KSampler\\\", \\\"pos\\\": [280, 320], \\\"size\\\": {\\\"0\\\": 315, \\\"1\\\": 474}, \\\"flags\\\": {}, \\\"order\\\": 3, \\\"mode\\\": 0, \\\"inputs\\\": [{\\\"name\\\": \\\"model\\\", \\\"type\\\": \\\"MODEL\\\", \\\"link\\\": 322}, {\\\"name\\\": \\\"positive\\\", \\\"type\\\": \\\"CONDITIONING\\\", \\\"link\\\": 327}, {\\\"name\\\": \\\"negative\\\", \\\"type\\\": \\\"CONDITIONING\\\", \\\"link\\\": 329}, {\\\"name\\\": \\\"latent_image\\\", \\\"type\\\": \\\"LATENT\\\", \\\"link\\\": 18}], \\\"outputs\\\": [{\\\"name\\\": \\\"LATENT\\\", \\\"type\\\": \\\"LATENT\\\", \\\"links\\\": [13, 109], \\\"shape\\\": 3, \\\"slot_index\\\": 0}], \\\"properties\\\": {\\\"Node name for S&R\\\": \\\"KSampler\\\"}, \\\"widgets_values\\\": [0, \\\"fixed\\\", 24, 7, \\\"dpmpp_2m\\\", \\\"karras\\\", 0.75]}, {\\\"id\\\": 22, \\\"type\\\": \\\"LatentMix_AS\\\", \\\"pos\\\": [479, -29], \\\"size\\\": {\\\"0\\\": 315, \\\"1\\\": 78}, \\\"flags\\\": {}, \\\"order\\\": 6, \\\"mode\\\": 0, \\\"inputs\\\": [{\\\"name\\\": \\\"samples_to\\\", \\\"type\\\": \\\"LATENT\\\", \\\"link\\\": 108}, {\\\"name\\\": \\\"samples_from\\\", \\\"type\\\": \\\"LATENT\\\", \\\"link\\\": 109}], \\\"outputs\\\": [{\\\"name\\\": \\\"LATENT\\\", \\\"type\\\": \\\"LATENT\\\", \\\"links\\\": [110], \\\"shape\\\": 3, \\\"slot_index\\\": 0}], \\\"properties\\\": {\\\"Node name for S&R\\\": \\\"LatentMix_AS\\\"}, \\\"widgets_values\\\": [75]}, {\\\"id\\\": 15, \\\"type\\\": \\\"PreviewImage\\\", \\\"pos\\\": [1251, 399], \\\"size\\\": [534.216472512637, 557.6668966527877], \\\"flags\\\": {}, \\\"order\\\": 4, \\\"mode\\\": 0, \\\"inputs\\\": [{\\\"name\\\": \\\"images\\\", \\\"type\\\": \\\"IMAGE\\\", \\\"link\\\": 19, \\\"slot_index\\\": 0}], \\\"properties\\\": {\\\"Node name for S&R\\\": \\\"PreviewImage\\\"}}, {\\\"id\\\": 11, \\\"type\\\": \\\"PreviewImage\\\", \\\"pos\\\": [1795, 405], \\\"size\\\": [516.968461609013, 545.2371885977157], \\\"flags\\\": {}, \\\"order\\\": 7, \\\"mode\\\": 0, \\\"inputs\\\": [{\\\"name\\\": \\\"images\\\", \\\"type\\\": \\\"IMAGE\\\", \\\"link\\\": 12}], \\\"properties\\\": {\\\"Node name for S&R\\\": \\\"PreviewImage\\\"}}, {\\\"id\\\": 14, \\\"type\\\": \\\"PreviewImage\\\", \\\"pos\\\": [2333, 400], \\\"size\\\": [519.1521322304691, 556.8946847014162], \\\"flags\\\": {}, \\\"order\\\": 11, \\\"mode\\\": 0, \\\"inputs\\\": [{\\\"name\\\": \\\"images\\\", \\\"type\\\": \\\"IMAGE\\\", \\\"link\\\": 17, \\\"slot_index\\\": 0}], \\\"properties\\\": {\\\"Node name for S&R\\\": \\\"PreviewImage\\\"}}, {\\\"id\\\": 20, \\\"type\\\": \\\"KSampler\\\", \\\"pos\\\": [898, 628], \\\"size\\\": {\\\"0\\\": 315, \\\"1\\\": 474}, \\\"flags\\\": {}, \\\"order\\\": 8, \\\"mode\\\": 0, \\\"inputs\\\": [{\\\"name\\\": \\\"model\\\", \\\"type\\\": \\\"MODEL\\\", \\\"link\\\": 323}, {\\\"name\\\": \\\"positive\\\", \\\"type\\\": \\\"CONDITIONING\\\", \\\"link\\\": 328}, {\\\"name\\\": \\\"negative\\\", \\\"type\\\": \\\"CONDITIONING\\\", \\\"link\\\": 330}, {\\\"name\\\": \\\"latent_image\\\", \\\"type\\\": \\\"LATENT\\\", \\\"link\\\": 110}], \\\"outputs\\\": [{\\\"name\\\": \\\"LATENT\\\", \\\"type\\\": \\\"LATENT\\\", \\\"links\\\": [35, 85], \\\"shape\\\": 3, \\\"slot_index\\\": 0}], \\\"properties\\\": {\\\"Node name for S&R\\\": \\\"KSampler\\\"}, \\\"widgets_values\\\": [1, \\\"fixed\\\", 24, 9, \\\"dpmpp_2m\\\", \\\"karras\\\", 0.55]}, {\\\"id\\\": 19, \\\"type\\\": \\\"WebuiParams\\\", \\\"pos\\\": [-293, 223.00000000000003], \\\"size\\\": {\\\"0\\\": 315, \\\"1\\\": 186}, \\\"flags\\\": {\\\"collapsed\\\": false}, \\\"order\\\": 1, \\\"mode\\\": 0, \\\"inputs\\\": [], \\\"outputs\\\": [{\\\"name\\\": \\\"MODEL\\\", \\\"type\\\": \\\"MODEL\\\", \\\"links\\\": [322, 323], \\\"shape\\\": 3, \\\"slot_index\\\": 0}, {\\\"name\\\": \\\"VAE\\\", \\\"type\\\": \\\"VAE\\\", \\\"links\\\": [324, 325, 326], \\\"shape\\\": 3, \\\"slot_index\\\": 1}, {\\\"name\\\": \\\"CONDITIONING\\\", \\\"type\\\": \\\"CONDITIONING\\\", \\\"links\\\": [327, 328], \\\"shape\\\": 3, \\\"slot_index\\\": 2}, {\\\"name\\\": \\\"CONDITIONING\\\", \\\"type\\\": \\\"CONDITIONING\\\", \\\"links\\\": [329, 330], \\\"shape\\\": 3, \\\"slot_index\\\": 3}], \\\"title\\\": \\\"WebuiParams\\\", \\\"properties\\\": {\\\"nestedData\\\": {\\\"nestedNodes\\\": [{\\\"id\\\": 7, \\\"type\\\": \\\"WebuiCheckpointLoader\\\", \\\"pos\\\": [-641.75, 129.62500000000006], \\\"size\\\": {\\\"0\\\": 315, \\\"1\\\": 98}, \\\"flags\\\": {\\\"collapsed\\\": false}, \\\"order\\\": 1, \\\"mode\\\": 0, \\\"outputs\\\": [{\\\"name\\\": \\\"MODEL\\\", \\\"type\\\": \\\"MODEL\\\", \\\"links\\\": [313, 314], \\\"shape\\\": 3, \\\"slot_index\\\": 0}, {\\\"name\\\": \\\"CLIP\\\", \\\"type\\\": \\\"CLIP\\\", \\\"links\\\": [311, 312], \\\"shape\\\": 3, \\\"slot_index\\\": 1}, {\\\"name\\\": \\\"VAE\\\", \\\"type\\\": \\\"VAE\\\", \\\"links\\\": [315, 316, 317], \\\"shape\\\": 3, \\\"slot_index\\\": 2}], \\\"properties\\\": {\\\"Node name for S&R\\\": \\\"WebuiCheckpointLoader\\\"}, \\\"widgets_values\\\": [\\\"0.8629134962031651692335312135\\\"]}, {\\\"id\\\": 8, \\\"type\\\": \\\"WebuiPrompts\\\", \\\"pos\\\": [-538.75, 288.45833333333337], \\\"size\\\": {\\\"0\\\": 315, \\\"1\\\": 78}, \\\"flags\\\": {\\\"collapsed\\\": false}, \\\"order\\\": 2, \\\"mode\\\": 0, \\\"outputs\\\": [{\\\"name\\\": \\\"positive\\\", \\\"type\\\": \\\"STRING\\\", \\\"links\\\": [309], \\\"shape\\\": 3, \\\"slot_index\\\": 0}, {\\\"name\\\": \\\"negative\\\", \\\"type\\\": \\\"STRING\\\", \\\"links\\\": [310], \\\"shape\\\": 3, \\\"slot_index\\\": 1}], \\\"properties\\\": {\\\"Node name for S&R\\\": \\\"WebuiPrompts\\\"}, \\\"widgets_values\\\": [\\\"0.73159882442417671692335312135\\\"]}, {\\\"id\\\": 10, \\\"type\\\": \\\"CLIPTextEncode\\\", \\\"pos\\\": [1.25, 173.45833333333337], \\\"size\\\": {\\\"0\\\": 210, \\\"1\\\": 54}, \\\"flags\\\": {\\\"collapsed\\\": false}, \\\"order\\\": 5, \\\"mode\\\": 0, \\\"inputs\\\": [{\\\"name\\\": \\\"clip\\\", \\\"type\\\": \\\"CLIP\\\", \\\"link\\\": 311}, {\\\"name\\\": \\\"text\\\", \\\"type\\\": \\\"STRING\\\", \\\"link\\\": 309, \\\"widget\\\": {\\\"name\\\": \\\"text\\\", \\\"config\\\": [\\\"STRING\\\", {\\\"multiline\\\": true}]}}], \\\"outputs\\\": [{\\\"name\\\": \\\"CONDITIONING\\\", \\\"type\\\": \\\"CONDITIONING\\\", \\\"links\\\": [318, 319], \\\"shape\\\": 3, \\\"slot_index\\\": 0}], \\\"properties\\\": {\\\"Node name for S&R\\\": \\\"CLIPTextEncode\\\"}, \\\"widgets_values\\\": [\\\"\\\"]}, {\\\"id\\\": 21, \\\"type\\\": \\\"CLIPTextEncode\\\", \\\"pos\\\": [7.25, 300.45833333333337], \\\"size\\\": {\\\"0\\\": 210, \\\"1\\\": 54}, \\\"flags\\\": {\\\"collapsed\\\": false}, \\\"order\\\": 6, \\\"mode\\\": 0, \\\"inputs\\\": [{\\\"name\\\": \\\"clip\\\", \\\"type\\\": \\\"CLIP\\\", \\\"link\\\": 312}, {\\\"name\\\": \\\"text\\\", \\\"type\\\": \\\"STRING\\\", \\\"link\\\": 310, \\\"widget\\\": {\\\"name\\\": \\\"text\\\", \\\"config\\\": [\\\"STRING\\\", {\\\"multiline\\\": true}]}}], \\\"outputs\\\": [{\\\"name\\\": \\\"CONDITIONING\\\", \\\"type\\\": \\\"CONDITIONING\\\", \\\"links\\\": [320, 321], \\\"shape\\\": 3, \\\"slot_index\\\": 0}], \\\"properties\\\": {\\\"Node name for S&R\\\": \\\"CLIPTextEncode\\\"}, \\\"widgets_values\\\": [\\\"\\\"]}]}}, \\\"widgets_values\\\": [\\\"0.81786936757995141692335377331\\\", \\\"0.59144547180798461692335377331\\\", \\\"\\\", \\\"\\\"]}], \\\"links\\\": [[12, 12, 0, 11, 0, \\\"IMAGE\\\"], [13, 6, 0, 12, 0, \\\"LATENT\\\"], [17, 13, 0, 14, 0, \\\"IMAGE\\\"], [18, 3, 0, 6, 3, \\\"LATENT\\\"], [19, 16, 0, 15, 0, \\\"IMAGE\\\"], [20, 3, 0, 16, 0, \\\"LATENT\\\"], [35, 20, 0, 13, 0, \\\"LATENT\\\"], [85, 20, 0, 4, 0, \\\"LATENT\\\"], [108, 3, 0, 22, 0, \\\"LATENT\\\"], [109, 6, 0, 22, 1, \\\"LATENT\\\"], [110, 22, 0, 20, 3, \\\"LATENT\\\"], [322, 19, 0, 6, 0, \\\"MODEL\\\"], [323, 19, 0, 20, 0, \\\"MODEL\\\"], [324, 19, 1, 16, 1, \\\"VAE\\\"], [325, 19, 1, 12, 1, \\\"VAE\\\"], [326, 19, 1, 13, 1, \\\"VAE\\\"], [327, 19, 2, 6, 1, \\\"CONDITIONING\\\"], [328, 19, 2, 20, 1, \\\"CONDITIONING\\\"], [329, 19, 3, 6, 2, \\\"CONDITIONING\\\"], [330, 19, 3, 20, 2, \\\"CONDITIONING\\\"]], \\\"groups\\\": [], \\\"config\\\": {}, \\\"extra\\\": {}, \\\"version\\\": 0.4}}\", Version: v1.5.1-RC-12-g68f336bd"; 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