Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
  • 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
Processing...

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 = "\\b\"{0,1}[A-Z0-9_][A-Z0-9._%+-]*[A-Z0-9_]\\@(?![. \\-])(([A-Z0-9-]+\\.)+[A-Z]{2,8}|\\[{0,1}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\\]{0,1})\\b"; final String string = "invalid formats\n" + "cf+2@3465456rteyaesrgrdsfgsdfg@thefloow.com\n" + "@@@\n" + "Leading dot in address eg .cf@thefloow.com\n" + "Trailing dot in address eg cf+.@thefloow.com\n" + "Multiple dots eg cf+..1@thefloow.com\n" + "Leading dash in front of domain eg cf@-thefloow.com\n" + "invalid top level domain names eg cf@thefloow.web\n" + "Multiple dots in the domain portion cf@thefloow..com\n" + "plainaddress Missing @ sign and domain\n" + "#@%^%#$@#$@#.com Garbage \n" + "@domain.com Missing username\n" + "Joe Smith <email@domain.com> Encoded html within email is invalid\n" + "email.domain.com Missing @\n" + "email@domain@domain.com Two @ sign \n" + ".email@domain.com Leading dot in address is not allowed\n" + "email.@domain.com Trailing dot in address is not allowe\n" + "email..email@domain.com Multiple dots\n" + "あいうえお@domain.com Unicode char as address \n" + "email@domain.com (Joe Smith) Text followed email is not allowed\n" + "email@domain Missing top level domain (.com/.net/.org/etc)\n" + "email@-domain.com Leading dash in front of domain is invalid \n" + "email@domain.web .web is not a valid top level domain\n" + "email@111.222.333.44444 Invalid IP format\n" + "email@domain..com Multiple dot in the domain portion is invalid\n" + "plainaddress\n" + "#@%^%#$@#$@#.com\n" + "@example.com\n" + "Joe Smith <email@example.com>\n" + "email.example.com\n" + "email@example@example.com\n" + ".email@example.com\n" + "email.@example.com\n" + "email..email@example.com\n" + "あいうえお@example.com\n" + "email@example.com (Joe Smith)\n" + "email@example\n" + "email@-example.com\n" + "email@example.web\n" + "email@111.222.333.44444\n" + "email@111.222.333.244\n" + "email@01.222.233.244\n" + "email@example..com\n" + "Abc..123@example.com\n" + "“(),:;<>[\\]@example.com\n" + "just\"not\"right@example.com\n" + "this\\ is\"really\"not\\allowed@example.com\n\n" + " \n" + "valid formats\n" + "ip address as domain name eg cf@192.168.0.1\n" + "quoted strings eg \"cf\"@thefloow.com \n" + "email@domain.com Valid email \n" + "firstname.lastname@domain.com Email contains dot in the address field \n" + "email@subdomain.domain.com Email contains dot with subdomain \n" + "firstname+lastname@domain.com Plus sign is considered valid character \n" + "email@123.123.123.123 Domain is valid IP address \n" + "email@[123.123.123.123] Square bracket around IP address is considered valid\n" + "\"email\"@domain.com Quotes around email is considered valid \n" + "1234567890@domain.com Digits in address are valid \n" + "email@domain-one.com Dash in domain name is valid \n" + "_______@domain.com Underscore in the address field is valid \n" + "email@domain.name .name is valid Top Level Domain name \n" + "email@domain.co.jp Dot in Top Level Domain name also considered valid (use co.jp as example here)\n" + "firstname-lastname@domain.com Dash in address field is valid\n" + "email@example.com\n" + "firstname.lastname@example.com\n" + "email@subdomain.example.com\n" + "firstname+lastname@example.com\n" + "email@123.123.123.0\n" + "email@[123.123.0.123]\n" + "email@123.0.123.123\n" + "email@[0.123.123.123]\n" + "“email”@example.com\n" + "1234567890@example.com\n" + "email@example-one.com\n" + "_______@example.com\n" + "email@example.name\n" + "email@example.museum\n" + "email@example.co.jp\n" + "3465456rteyaesrgrdsfgsdfg@thefloow.com\n" + "firstname-lastname@example.com\n" + "much.“more\\ unusual”@example.com\n" + "very.unusual.“@”.unusual.com@example.com\n" + "very.“(),:;<>[]”.VERY.“very@\\\\ \"very”.unusual@strange.example.com"; final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); 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