Regular Expressions 101

Save & Share

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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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
No Match

r"
"
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 = "\\\"Comment\\\": \\\"(.*?)\\\""; final String string = "[{\"Comment\": \"Tbh the chair should\\u2019ve had 4 pistons so Michael could finally eat at the table\", \"Likes\": \"4.4K\", \"Time\": \"2 years ago\", \"UserLink\": \"https://www.youtube.com/channel/UC_aU3uhZDInQSUUosL2uQ9A\", \"user\": \"Nates\"}, {\"Comment\": \"I want to believe that this isn't a screen personality and he is just a genuine sociopath\", \"Likes\": \"4.3K\", \"Time\": \"7 months ago\", \"UserLink\": \"https://www.youtube.com/channel/UCQBxoqlTxL2YNIm_p6FAEfw\", \"user\": \"tank head\"}, {\"Comment\": \"Can you build a chair that when you say \\u201cI\\u2019d like to make an announcement.\\u201d Pistons push the chair up to make you taller than everyone else\", \"Likes\": \"1.9K\", \"Time\": \"7 months ago\", \"UserLink\": \"https://www.youtube.com/channel/UC3HyXTP6aLjcZp88iOuytpg\", \"user\": \"Kitsune\"}, {\"Comment\": \"the tazer desk could easily be converted to a torture bed\", \"Likes\": \"245\", \"Time\": \"3 months ago\", \"UserLink\": \"https://www.youtube.com/channel/UCySFNMcZJm4MWAfiaIRpqvg\", \"user\": \"Cpt_Azure\"}, {\"Comment\": \"I want to imagine that his friends are just locked up in a house threatened hostage and forced to test his robot inventions\", \"Likes\": \"1.8K\", \"Time\": \"1 year ago\", \"UserLink\": \"https://www.youtube.com/channel/UCHZ6qYCGHm44ge2OGGazSVw\", \"user\": \"W\"}, {\"Comment\": \"\\\"I spent 12 hours making this...\\\"And 11 months tracking a goldfish in a cage...\", \"Likes\": \"492\", \"Time\": \"3 months ago\", \"UserLink\": \"https://www.youtube.com/channel/UCpNND06DunvPMGrSQqjjM_Q\", \"user\": \"Joshbobosh\"}, {\"Comment\": \"He should've added a delay to the chair so people get lured into a false sense of security\", \"Likes\": \"4.7K\", \"Time\": \"1 year ago\", \"UserLink\": \"https://www.youtube.com/channel/UCESk3Y2OfMMIgfATOsujI6Q\", \"user\": \"AshIsHere\"}, {\"Comment\": \"It's funny how Yvonne says \\\"Is that an electric chair?!\\\", And then he goes and builds one like a year later\", \"Likes\": \"3K\", \"Time\": \"11 months ago\", \"UserLink\": \"https://www.youtube.com/channel/UCol-DCuwRT0sS98uBu1oCBA\", \"user\": \"MrMoo1452\"}, {\"Comment\": \"\\u201cThat is a fuCKING alarm clock.\\u201dI love that quote so much\", \"Likes\": \"919\", \"Time\": \"6 months ago\", \"UserLink\": \"https://www.youtube.com/channel/UCuVPAzq8ORnoK8CcEDpTmHA\", \"user\": \"Bababooey\"}, {\"Comment\": \"I had an art teacher who said, \\\"Don't lean on the table!\\\" She was very angry when people did, and I'm assuming she would actually use the tazer table.\", \"Likes\": \"79\", \"Time\": \"5 months ago\", \"UserLink\": \"https://www.youtube.com/channel/UCCzciQr3PjMlYqbMmyjtgDg\", \"user\": \"Tom Kas\"}, {\"Comment\": \"Make your windshield wipers, automatically wipe in the beat of the music that is played in the car.\", \"Likes\": \"3.4K\", \"Time\": \"1 year ago\", \"UserLink\": \"https://www.youtube.com/channel/UCUfdOys12cHo7waaWkjG4mA\", \"user\": \"Benni B.\"}, {\"Comment\": \"Make a robot that automatically \\u201cpermanently removes\\u201d people who suggest an idea for a robot\", \"Likes\": \"84\", \"Time\": \"3 months ago\", \"UserLink\": \"https://www.youtube.com/channel/UCOh33A3iLMokwaUXI0Y6e6g\", \"user\": \"Swish_Cheetah\"}, {\"Comment\": \"I like that Michael calls us his \\\"worst, most hated enemies\\\".\\nYou can really feel the love.\", \"Likes\": \"900\", \"Time\": \"2 years ago\", \"UserLink\": \"https://www.youtube.com/channel/UCeOSKFvurM-glO4TW8SX3EA\", \"user\": \"Camera Lizard\"}, {\"Comment\": \"\\\"Make a robot that poops cereal\\\"shredded\\\"Make a robot that piss beer\\\"genius\", \"Likes\": \"361\", \"Time\": \"11 months ago\", \"UserLink\": \"https://www.youtube.com/channel/UCbSIk0yT8w-sVCI_wNsQkPA\", \"user\": \"Ghedo\"}, {\"Comment\": \"ya gotta love the fact that the taser desk was acting as an EMP that caused his monitor to shut off several times\", \"Likes\": \"626\", \"Time\": \"10 months ago\", \"UserLink\": \"https://www.youtube.com/channel/UCmqGYYVwZ0nrd5tIxazWddA\", \"user\": \"Jackie\"}, {\"Comment\": \"I like that the Taser Desk incorporates so much high voltage garbage that it\\u2019s making the electronics in his computer spaz out lmao. Who doesn\\u2019t love a bad homemade EMP\", \"Likes\": \"4\", \"Time\": \"12 days ago\", \"UserLink\": \"https://www.youtube.com/channel/UCfvtdRAITOtzjZIgoKmCK5w\", \"user\": \"SilentGuy\"}, {\"Comment\": \"The fact everyone fears Michael is just hilarious\", \"Likes\": \"224\", \"Time\": \"7 months ago\", \"UserLink\": \"https://www.youtube.com/channel/UCzdTkBuxvZhOGQAN6eUsfWA\", \"user\": \"ipikalive\"}, {\"Comment\": \"I love how the taser desk literally constantly has sparks coming off of it which looks amazing, this is all thanks to that one comment\", \"Likes\": \"34\", \"Time\": \"3 months ago (edited)\", \"UserLink\": \"https://www.youtube.com/channel/UC_P1bdtzQhDgAnEZn1TyoBw\", \"user\": \"So confused\"}, {\"Comment\": \"Build something that looks absolutely terrifying but does nothing and just makes your friends paranoid\", \"Likes\": \"29K\", \"Time\": \"2 years ago\", \"UserLink\": \"https://www.youtube.com/channel/UCqMzTW0oC7B7HM6v8iiWIpg\", \"user\": \"Jerry Kat\"}, {\"Comment\": \"I love how everyone Michael knows is immediately scared when he talks to them\", \"Likes\": \"403\", \"Time\": \"1 year ago\", \"UserLink\": \"https://www.youtube.com/channel/UCqHG4WQJ7S3tUUo895WFBtQ\", \"user\": \"Evan Thorne\"}]"; 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