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 (10)

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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])[\\w!@#$%]{6,}$"; final String string = "INVALID:\n" + "abcdefg\n" + "abc\n" + "abcdefghji\n" + "abCDEFghij\n" + "1234efghij\n" + "abcde6789\n" + "ab!67fghij\n" + "ab)=\n\n" + "VALID:\n" + "8vB0k3XiLp\n" + "VvsfM5he#X\n" + "d10STfJ$gA\n" + "R1cIX7mn8T\n" + "6EDNTbda%z\n" + "IKkED0#zYS\n" + "1S#9duFcHe\n" + "KP1fN3jTwJ\n" + "iRS1YB@nfI\n" + "Vp1yRxwuGD\n" + "fajT2ukURg\n" + "9tY8#HkojR\n" + "@LHTbA3C7J\n" + "%HLK6EqANV\n" + "#vZR6in5KJ\n" + "!WwjH3K65v\n" + "%5WOIrCv@R\n" + "emfpLRE5oD\n" + "zREw13rcJn\n" + "#NU42oxYa0\n" + "$oujwK%xR7\n" + "1YH#uOFQlV\n" + "L936DS2ynR\n" + "ab4RAVCZHv\n" + "9xwiZmDSAd\n" + "eZjPHg3B8i\n" + "OANw!p8yxH\n" + "J6efM@hxNz\n" + "qvmefZI3Wn\n" + "fH9wXGK8ZI\n" + "eHcl3qRYGS\n" + "i8we0zpOvr\n" + "1kpSFgeIKA\n" + "p8eM@FtZ9n\n" + "rj95zq!E3I\n" + "lkDKt@486w\n" + "7!j50lyxgB\n" + "%vBCxLq6Ym\n" + "@ky$u9iSGm\n" + "%QD9jA6Lm@\n" + "JolTzf7gUr\n" + "cSRe%v46Or\n" + "oJVlc#Gdn3\n" + "G!%NF0XESp\n" + "76dMFmbf%X\n" + "3JQlSRiXLj\n" + "Y$!%WCgti0\n" + "D1k$#ThiqG\n" + "M6tPY$XzQp\n" + "@gUcrWm7zA\n" + "1xc#hwGj0D\n" + "s8p#S$ZkWP\n" + "sIP3dQL#4j\n" + "bBLEnvlFI3\n" + "isSeP4AC%w\n" + "1OsdI4iCjR\n" + "@p#qm$NA9Z\n" + "guPjtIp5!i\n" + "a84ONQRZXY\n" + "homJ9T6w80\n" + "$!uh09kaUO\n" + "CTIX7vsalJ\n" + "2CASR7IUyY\n" + "Tr1jl!oKPF\n" + "2%ar6kMCZe\n" + "m4TrLJC!cD\n" + "3E#mZ!jrdn\n" + "oZIa$xmDU8\n" + "9wXxBaJAyz\n" + "0%dNQfyr$e\n" + "ez#IcxH8SX\n" + "MF$m6wile%\n" + "ilo3FURh9t\n" + "d71hgGe5Vo\n" + "KEr9u7CRtP\n" + "CfUE4Fj$Ju\n" + "aXSG5wIQor\n" + "VTk2fmDlbx\n" + "GHxBwpt0dN\n" + "mYS2Q1zFi!\n" + "qD0KiayFz4\n" + "hT9FrGQ$dS\n" + "5eKrEvnBZA\n" + "gA$fXPUd2#\n" + "Eoz8uqBART\n" + "7wKEo6jJGX\n" + "1p4Zj7Ssk2\n" + "K#MX8Q61dr\n" + "L%S2Kh7Q@r\n" + "fwD6zy$NM@\n" + "zyJPri5u7N\n" + "MyAI!j2iz%\n" + "9blWdD5!w@\n" + "iw6Ef3dBLk\n" + "JMYD1iHol2\n" + "#M1OUJ0VDi\n" + "e@78BCHLI%\n" + "oeD1F!4ifz\n" + "pCblno9zyJ\n" + "FJKErsBTp6"; 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