Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • 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

/
/
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 = "((?:(?:123456)|(?:1[2-5]*)|(?:[2-5]*6)) )"; final String string = "12456 123456 34 1236 123456 1234 45 123456 whitings\n" + "14 356 124 6 12345 6 1245 malformations\n" + "12456 23456 2356 12345 12345 123456 6 furnishings\n" + "12456 34 34 356 12356 15 26 13 gastrointestinal\n" + "23456 1 234 3 5 12356 lawyer\n" + "2356 345 12345 4 4 1 6 gripped\n" + "1 236 145 23 16 4 12356 4 3 packers\n" + "1245 146 2 2 23 126 1235 2356 4 3 outrun\n\n" + "should not match ^\n\n" + "123456 123456 123456 123456 35 12456 123456 123456 23 356 23456 25 replenishes\n" + "3456 45 35 12456 1346 256 2356 123456 1236 123456 1346 flophouse\n" + "356 123456 56 12356 4 3 2356 6 12456 1246 12356 footsteps\n" + "123456 156 2356 136 123456 146 123456 5 12356 123456 1456 expurgations\n" + "12346 2 2346 123456 2356 56 245 12346 13456 12456 misidentifies\n" + "1256 345 24 12456 12356 123456 12356 356 1256 5 26 swine\n" + "123456 45 456 12346 136 12346 6 24 12346 4 56 235 extremists\n" + "346 1236 2356 13456 123456 23456 1346 1256 123456 24 346 245 hexagonal\n\n" + "14 23456 12356 1234 15 1456 1245 123456 23456 chrysanthemums\n" + "245 34 123456 123456 12 346 134 4 245 1245 146 6 gravitate\n" + "346 1245 136 23456 5 1356 123456 5 123456 123456 octettes\n" + "134 3456 15 15 46 34 123456 123456 3456 246 quasar\n" + "123456 35 123456 123456 123456 1245 123456 12456 1 surprisings\n" + "356 12346 1246 1235 4 12356 2 13456 13456 236 emptied\n" + "23456 2356 12456 134 2356 256 12456 12346 1 13 ennoblement\n" + "123456 235 16 5 13456 15 2 1456 12356 3456 3 123456 quadratic\n\n" + "should match ^"; 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