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 = '/(?<=\"text\": \")(.*?hello.*?)(?=", \"type\": \"text\")/m'; $str = '{"root": {"type": "root", "format": "", "indent": 0, "version": 1, "children": [{"type": "paragraph", "format": "", "indent": 0, "version": 1, "children": [{"mode": "normal", "text": "text1 hello text", "type": "text", "style": "", "detail": 0, "format": 0, "version": 1}], "direction": "ltr"}], "direction": "ltr"}} hellocat world f {"root": {"type": "root", "format": "", "indent": 0, "version": 1, "children": [{"type": "paragraph", "format": "", "indent": 0, "version": 1, "children": [{"src": "https://images.unsplash.com/photo-1458966480358-a0ac42de0a7a?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w1MjU5NTl8MHwxfHNlYXJjaHwzfHx0cmVlfGVufDB8fHx8MTcxMzk5MjE4OHww&ixlib=rb-4.0.3&q=80&w=1080", "type": "image", "width": 332, "height": "221.329875", "version": 1, "alt_text": "image", "max_width": 500}, {"mode": "normal", "text": "dsadsa", "type": "text", "style": "", "detail": 0, "format": 0, "version": 1}], "direction": "ltr"}, {"type": "paragraph", "format": "", "indent": 0, "version": 1, "children": [{"mode": "normal", "text": "fdsfds", "type": "text", "style": "", "detail": 0, "format": 0, "version": 1}], "direction": "ltr"}], "direction": "ltr"}} {"root": {"type": "root", "format": "", "indent": 0, "version": 1, "children": [{"type": "paragraph", "format": "", "indent": 0, "version": 1, "children": [{"mode": "normal", "text": "nccccchello ddddd", "type": "text", "style": "", "detail": 0, "format": 0, "version": 1}], "direction": "ltr"}], "direction": "ltr"}} {"root": {"type": "root", "format": "", "indent": 0, "version": 1, "children": [{"tag": null, "type": "paragraph", "start": null, "format": "", "indent": 0, "version": 1, "children": [{"rel": null, "src": null, "url": null, "mode": "normal", "text": "bvcbvc", "type": "text", "style": "", "title": null, "value": null, "width": null, "detail": 0, "format": 0, "height": null, "indent": null, "inline": null, "target": null, "checked": null, "version": 1, "alt_text": null, "children": null, "equation": null, "field_id": null, "direction": null, "max_width": null, "field_name": null, "field_type": null, "highlight_type": null, "hidden_field_name": null, "hidden_field_value": null}], "language": null, "video_id": null, "direction": "ltr", "list_type": null}], "direction": "ltr"}} {"root": {"type": "root", "format": "", "indent": 0, "version": 1, "children": [{"tag": null, "type": "paragraph", "start": null, "format": "", "indent": 0, "version": 1, "children": [{"rel": null, "src": null, "url": null, "mode": "normal", "text": "gbfbvc", "type": "text", "style": "", "title": null, "value": null, "width": null, "detail": 0, "format": 0, "height": null, "indent": null, "inline": null, "target": null, "checked": null, "version": 1, "alt_text": null, "children": null, "equation": null, "field_id": null, "direction": null, "max_width": null, "field_name": null, "field_type": null, "highlight_type": null, "hidden_field_name": null, "hidden_field_value": null}], "language": null, "video_id": null, "direction": "ltr", "list_type": null}], "direction": "ltr"}}'; 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