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

r"
"
gms

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 = "##Player Stats\\n(.*?)##Goalie Stats"; final String string = "[](#startinjuredreserve)\n\n" + "##Injured Reserve\n" + "|Position|Player|Salary|\n" + "|:-|:-|:-|\n" + "|RD|Oscar Fantenberg|$850,000|\n" + "|LW|Antoine Roussel|$3,000,000|\n\n\n" + "[](#endinjuredreserve)\n\n" + "[](#startmagicalbotarea)\n\n\n" + "##Schedule\n" + "|Date|Time|Opponent|TV/Score|\n" + "|::|::|::|::|\n" + "|15 Oct|19:00|vs [Detroit Red Wings](/r/detroitredwings \"Detroit Red Wings\")|**W 5-1**|\n" + "|17 Oct|17:00|@ [St. Louis Blues](/r/stlouisblues \"St. Louis Blues\")|**W 4-3**|\n" + "|19 Oct|10:00|@ [New Jersey Devils](/r/devils \"New Jersey Devils\")|L 1-0|\n" + "|**Today**|10:00|@ [New York Rangers](/r/rangers \"New York Rangers\")|**W 3-2**|\n" + "|22 Oct|16:30|@ [Detroit Red Wings](/r/detroitredwings \"Detroit Red Wings\")|SN360|\n" + "|25 Oct|19:00|vs [Washington Capitals](/r/caps \"Washington Capitals\")|SN1|\n" + "|28 Oct|19:00|vs [Florida Panthers](/r/floridapanthers \"Florida Panthers\")|SNP|\n\n" + "##Pacific Standings\n" + "|Team|GP|W|L|OTL|PTS|Streak\n" + "|::|::|::|::|::|::|::|\n" + "|[Edmonton Oilers](/r/edmontonoilers \"Edmonton Oilers\")|8|7|1|0|14|W2|\n" + "|[Anaheim Ducks](/r/anaheimducks \"Anaheim Ducks\")|8|6|2|0|12|W2|\n" + "|[Vegas Golden Knights](/r/goldenknights \"Vegas Golden Knights\")|9|6|3|0|12|W2|\n" + "|[Vancouver Canucks](/r/canucks \"Vancouver Canucks\")|8|5|3|0|10|W1|\n" + "|[Arizona Coyotes](/r/coyotes \"Arizona Coyotes\")|7|4|2|1|9|W3|\n" + "|[Calgary Flames](/r/calgaryflames \"Calgary Flames\")|9|4|4|1|9|L1|\n" + "|[San Jose Sharks](/r/sanjosesharks \"San Jose Sharks\")|8|3|5|0|6|L1|\n" + "|[Los Angeles Kings](/r/losangeleskings \"Los Angeles Kings\")|8|3|5|0|6|W1|\n\n" + "##Player Stats\n" + "Player|GP|G|A|P|+/-|PIM|\n" + "|:|::|::|::|::|::|::|\n" + "|Miller|8|4|4|**8**|5|4|\n" + "|Pettersson|8|2|6|**8**|4|0|\n" + "|Boeser|8|2|5|**7**|4|0|\n" + "|Edler|8|3|3|**6**|-1|10|\n" + "|Sutter|8|2|3|**5**|1|7|\n" + "|Pearson|8|2|2|**4**|-4|2|\n" + "|Tanev|8|1|3|**4**|1|0|\n" + "|Hughes|8|1|3|**4**|1|2|\n" + "|Horvat|8|2|1|**3**|0|2|\n" + "|Leivo|8|1|2|**3**|1|2|\n\n" + "##Goalie Stats\n" + "|Goalie|GP|W|L|SV%|GAA|SO|\n" + "|:|::|::|::|::|::|::|\n" + "|Markstrom|5|3|2|0.932|2.19|0|\n" + "|Demko|3|2|1|0.943|1.64|0|\n\n" + "*****\n" + "Updated at: 20 Oct 2019, 03:12 PM PST\n" + "*****\n\n" + "[](#endmagicalbotarea)\n\n" + "##Filter Options\n" + "- If you want to block a certain type of posts, click one of the link filters below\n\n" + "- [No Shitpost/Memes](https://nm.reddit.com/r/canucks/#nm)\n\n" + "- [No Fan Content](https://nf.reddit.com/r/canucks/#nf)\n\n" + "- [No Memes or Fan Content](https://mf.reddit.com/r/canucks/#mf)\n\n" + "- [Reset Filter](https://reddit.com/r/canucks/)\n\n" + "## Links & Resources\n\n" + "- /r/hockey\n" + "- /r/UticaComets\n" + "- /r/TheAthleticVAN \n" + "- [Canucks Capfriendly](https://www.capfriendly.com/teams/canucks)\n" + "- [Canucks.com](https://www.nhl.com/canucks)\n" + "- [Canucks Official Twitter](https://twitter.com/canucks)\n" + "- [Canucks Official YT Channel](http://www.youtube.com/user/Canucks)\n" + "- [Sportsnet 650 Vancouver](http://www.sportsnet.ca/650/)\n" + "- [TSN 1040](http://www.tsn.ca/radio/vancouver-1040-i-1410)\n" + "- [**Join /r/Canucks Discord!**] (https://discord.gg/UTZ5Vrb)\n\n" + "## Subreddit Wiki\n\n" + "- [Rules and Guidelines](/r/canucks/wiki/rules)\n" + "- [Streaming Guide](/r/canucks/wiki/streaming)\n" + "- [Attending a Canucks Game?](/r/canucks/comments/2u5lxr/so_you_wanna_go_to_a_canucks_game_eh_faq_for/)\n" + "- [Canucks Resources](/r/canucks/wiki/resources)\n" + "- [Meme Hall of Fame](/r/canucks/wiki/memes)\n" + "- [AMA Archive](/r/canucks/wiki/amas)\n" + "- [**Nostalgia Corner**](https://www.reddit.com/r/canucks/wiki/nostalgia-corner)"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL); 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