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"
"
g

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 = "\\{\\{MSP\\|\\d\\d\\d\\|([\\w é \\' \\. \\-]+)\\}\\}"; final String string = "====By {{pkmn|breeding}}====\n" + "{{learnlist/breedh/6|Aipom|Normal|Normal|2|xy=n}}\n" + "{{learnlist/breed6|{{MSP|025|Pikachu}}{{MSP|058|Growlithe}}{{MSP|077|Ponyta}}{{MSP|078|Rapidash}}{{MSP|083|Farfetch'd}}{{MSP|135|Jolteon}}<br>{{MSP|190|Aipom}}{{MSP|424|Ambipom}}{{MSP|203|Girafarig}}{{MSP|215|Sneasel}}{{MSP|418|Buizel}}{{MSP|419|Floatzel}}<br>{{MSP|427|Buneary}}{{MSP|428|Lopunny}}{{MSP|522|Blitzle}}{{MSP|523|Zebstrika}}{{MSP|570|Zorua}}{{MSP|571|Zoroark}}<br>{{MSP|587|Emolga}}{{MSP|659|Bunnelby}}{{MSP|660|Diggersby}}|Agility|Psychic|Status|&mdash;|&mdash;|30|||Cool|3|0}}\n" + "{{learnlist/breed6|{{MSP|077|Ponyta}}{{MSP|078|Rapidash}}{{MSP|320|Wailmer}}{{MSP|321|Wailord}}{{MSP|325|Spoink}}{{MSP|326|Grumpig}}<br>{{MSP|427|Buneary}}{{MSP|428|Lopunny}}{{MSP|619|Mienfoo}}{{MSP|620|Mienshao}}{{MSP|659|Bunnelby}}{{MSP|660|Diggersby}}|Bounce|Flying|Physical|85|85|5|||Cute|1|0}}\n" + "{{learnlist/breed6|{{MSP|287|Slakoth}}{{MSP|288|Vigoroth}}{{MSP|289|Slaking}}{{MSP|448|Lucario}}|Counter|Fighting|Physical|&mdash;|100|20|||Tough|2|0}}\n" + "{{learnlist/breed6|{{MSP|056|Mankey}}{{MSP|133|Eevee}}{{MSP|216|Teddiursa}}{{MSP|217|Ursaring}}{{MSP|263|Zigzagoon}}{{MSP|264|Linoone}}<br>{{MSP|287|Slakoth}}{{MSP|289|Slaking}}{{MSP|300|Skitty}}{{MSP|677|Espurr}}{{MSP|678|Meowstic}}|Covet|Normal|Physical|60|100|25||'''|Cute|1|0}}\n" + "{{learnlist/breed6|{{MSP|300|Skitty}}{{MSP|301|Delcatty}}{{MSP|572|Minccino}}{{MSP|619|Mienfoo}}{{MSP|620|Mienshao}}{{MSP|659|Bunnelby}}|Double Slap|Normal|Physical|15|85|10||'''|Cute|1|0}}\n" + "{{learnlist/breed6|{{MSP|052|Meowth}}{{MSP|053|Persian}}{{MSP|274|Nuzleaf}}{{MSP|300|Skitty}}{{MSP|301|Delcatty}}{{MSP|431|Glameow}}<br>{{MSP|432|Purugly}}{{MSP|509|Purrloin}}{{MSP|510|Liepard}}{{MSP|619|Mienfoo}}{{MSP|620|Mienshao}}{{MSP|677|Espurr}}<br>{{MSP|678|Meowstic}}|Fake Out|Normal|Physical|40|100|10||'''|Cute|2|3}}\n" + "{{learnlist/breed6|{{MSP|019|Rattata}}{{MSP|020|Raticate}}{{MSP|128|Tauros}}{{MSP|197|Umbreon}}{{MSP|206|Dunsparce}}{{MSP|335|Zangoose}}<br>{{MSP|359|Absol}}{{MSP|418|Buizel}}{{MSP|419|Floatzel}}{{MSP|509|Purrloin}}{{MSP|510|Liepard}}{{MSP|522|Blitzle}}<br>{{MSP|523|Zebstrika}}{{MSP|570|Zorua}}{{MSP|571|Zoroark}}{{MSP|587|Emolga}}{{MSP|626|Bouffalant}}|Pursuit|Dark|Physical|40|100|20|||Clever|2|1}}\n" + "{{learnlist/breed6|{{MSP|448|Lucario}}{{MSP|619|Mienfoo}}{{MSP|678|Meowstic}}|Quick Guard|Fighting|Status|&mdash;|&mdash;|15|||Cool|2|0}}\n" + "{{learnlist/breed6|{{MSP|335|Zangoose}}{{MSP|461|Weavile}}{{MSP|501|Oshawott}}{{MSP|502|Dewott}}{{MSP|503|Samurott}}{{MSP|626|Bouffalant}}|Revenge|Fighting|Physical|60|100|10|||Tough|2|0}}\n" + "{{learnlist/breed6|{{MSP|023|Ekans}}{{MSP|024|Arbok}}{{MSP|052|Meowth}}{{MSP|053|Persian}}{{MSP|054|Psyduck}}{{MSP|055|Golduck}}<br>{{MSP|056|Mankey}}{{MSP|057|Primeape}}{{MSP|190|Aipom}}{{MSP|424|Ambipom}}{{MSP|197|Umbreon}}{{MSP|206|Dunsparce}}<br>{{MSP|215|Sneasel}}{{MSP|461|Weavile}}{{MSP|293|Whismur}}{{MSP|294|Loudred}}{{MSP|295|Exploud}}{{MSP|336|Seviper}}<br>{{MSP|352|Kecleon}}{{MSP|434|Stunky}}{{MSP|435|Skuntank}}|Screech|Normal|Status|&mdash;|85|40|||Clever|3|0}}\n" + "{{learnlist/breed6|{{MSP|025|Pikachu}}{{MSP|161|Sentret}}{{MSP|162|Furret}}{{MSP|194|Wooper}}{{MSP|195|Quagsire}}{{MSP|231|Phanpy}}<br>{{MSP|232|Donphan}}{{MSP|495|Snivy}}{{MSP|496|Servine}}{{MSP|497|Serperior}}{{MSP|504|Patrat}}{{MSP|505|Watchog}}<br>{{MSP|572|Minccino}}|Slam|Normal|Physical|80|75|20||'''|Tough|4|0}}\n" + "{{learnlist/breed6|{{MSP|206|Dunsparce}}|Spite|Ghost|Status|&mdash;|100|10|||Tough|2|1}}\n" + "{{learnlist/breed6|{{MSP|053|Persian}}{{MSP|264|Linoone}}{{MSP|655|Delphox}}|Switcheroo|Dark|Status|&mdash;|100|10|||Clever|2|1}}\n" + "{{learnlist/breedf/6|Aipom|Normal|Normal|2}}\n"; final Pattern pattern = Pattern.compile(regex); 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