Regular Expressions 101

Save & Share

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

/
/

Test String

Code Generator

Generated Code

$re = '/\{(?:[^{}]|(?R))*\}/'; $str = '<think> Alright, so I need to help create a list of five top kids stories in JSON format. The user has provided some data: story idea, story caption, story environment prompt, and duration in seconds. They also shared an example response with those elements. First, I should understand the structure they are asking for. It looks like each entry is an object within a "stories" array. Each object has four keys: "story_idea", "story_caption", "story_environment_prompt", and "duration". The values are strings or integers. They already have five examples in their initial response, so I can model my answer after that. But wait, the user has not given me any specific story ideas yet—do they want me to come up with new ones? Or did they just provide an example? It seems like maybe they want the assistant to generate these on the spot. I should ask if they need more specific stories or if five random ones are sufficient. However, since I am supposed to imagine a thought process where I might think through creating such data, perhaps I can outline how each story is built. For "story_idea", it is about what the main plot revolves around. For example, an adventure, mystery, friendship, etc. The "story_caption" is a brief summary of the story. The environment prompt describes where the action takes place, and duration gives how long it runs if performed live. I should make sure each JSON object follows this structure correctly. Also, since they provided example stories with varying themes, I can include different genres to keep them interesting. Perhaps one could be about a magical forest adventure, another a superhero quest, then maybe a pirate treasure hunt, an animal rescue mission, and a space exploration. These cover various age-appropriate themes for kids. I need to ensure the story captions are engaging and concise, fitting within the JSON format without any markdown or extra formatting. Each environment prompt should paint a clear picture of where the action happens. Also, durations vary from 1:30 to 2:50 minutes—this gives an idea of how long each segment might take if acted out live. I will structure each entry accordingly, making sure all fields are correctly filled with appropriate values. It is important that the JSON is valid and well-formatted so it can be easily parsed or used elsewhere without issues. </think> Here is a JSON-formatted list of five kids stories based on various themes: ```json stories = [ { "story_idea": "A magical forest adventure where children meet talking animals.", "story_caption": "In the Enchanted Forest, a group of kids discover magical creatures who help them solve puzzles to find their way home.", "story_environment_prompt": "Enchanted Forest with glowing plants and singing animals.", "duration": 180 }, { "story_idea": "A superhero quest to save the city from a shadowy villain.", "story_caption": "The kids become superheroes, training hard and using their unique powers to stop a plan that could take over the city.", "story_environment_prompt": "City streets with tall buildings and bright lights.", "duration": 210 }, { "story_idea": "A pirate treasure hunt around an old, rusted ship.", "story_caption": "The kids follow a map to find hidden treasures on an old shipwreck, facing challenges like decoding messages and avoiding dangers.", "story_environment_prompt": "An old, rusted ship with maps and treasure chests.", "duration": 190 }, { "story_idea": "A day at the zoo where kids interact with different animals.", "story_caption": "At the zoo, children meet elephants, monkeys, and zebras, learning about each animal while having fun.", "story_environment_prompt": "Zoo with various animals in their enclosures.", "duration": 160 }, { "story_idea": "An alien rescue mission where kids meet an alien child who needs help returning to their home planet.", "story_caption": "The kids, with the help of a friendly alien companion, set out to rescue a trapped alien child and bring them back to their home world.", "story_environment_prompt": "Alien planet with rolling hills and floating islands.", "duration": 170 } ] ``` This JSON structure includes five distinct stories each with a unique theme, ensuring variety for different age groups and interests. Each story is crafted to be engaging and appropriate for children while providing clear details about the setting and duration.'; preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 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