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
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 = "(\\d{5,}\\S+)(?:-REV)|(\\d{5,})|(\\d.+)(?:-REV).+|(\\b[A-Za-z0-9]+-[A-Za-z0-9]+-[A-Za-z0-9]+\\b)|(\\d{4,}.\\S+)"; final String string = "SIEMENS10249071REV05\n" + "22D1496-REV-A\n" + "SANTASISE398FOP4\n" + "KCC C318-M-2328\n" + "22006-17114-REV-0\n" + "WELD30\n" + "2328ENDFIN\n" + "OSH4780973\n" + "10520398ITEM7\n" + "KCC C153-M-136290\n" + "2373 TAPER\n" + "SANTA ISE398 R2\n" + "SANTASISE398RGH1\n" + "34F0-010-102-REV-WELDMENT\n" + "14A1936D1F1-REV-NONE\n" + "6181194-REV-B\n" + "PRETE WT-80-1015BLIND\n" + "MAXAM340000566\n" + "SHARPE-36465 1ST\n" + "OSH 3899580\n" + "7494-03-301-REV-NONE\n" + "MAXAM340000566OP2\n" + "KCC C318-M-2373TAPER\n" + "CARDINAL36465\n" + "SIEMENS-10248227 REV.8\n" + "4212.8842-REV-Q\n" + "14A1936-REV-NONE\n" + "LATHE TOOL\n" + "360 YIELD 450111 RH MAIN PROGRAM;360 YIELD 450111 LH MAIN PROGRAM;450111\n" + "KCC C318-M-2373\n" + "360 YIELD 450211 RH MAIN PROGRAM;360 YIELD 450211 LH MAIN PROGRAM;450211\n" + "360 YIELD 450101 LH MAIN PROGRAM;450101\n" + "10753289-REV-02\n" + "30613D3-REV-05\n" + "30613D4-REV-05\n" + "OSHKOSH CORP/4381568/REV B/OP 1\n" + "OSHKOSH/12611249/REV A/OP1\n" + "14A1669 COVER-REV-J\n" + "OSH 4641290\n" + "KCC C318-M-2372\n" + "2328 FINISH\n" + "10751755-REV-2\n" + "312-133001-001-REV-D\n" + "KOOTR KT300AL OP1\n" + "OSHKOSH CORP/4381568/REV B/OP 2\n" + "360 YIELD 450201 LH MAIN PROGRAM;360 YIELD 450201 RH MAIN PROGRAM;450201\n" + "OSH 3899580OP2\n" + "10520398ITEM17\n" + "WELD30BIG\n" + "2347337-01-REV-NONE\n" + "2372 FINISH\n" + "10753199-02-REV-7\n" + "OSH 1693510\n" + "2328END\n" + "OSH 4384499OP2\n" + "E4-TKD-Z002A00KP;E4-TKD-ZOO2AOO WITH TRANSFER\n" + "10753199-02-REV-6\n" + "OSH 4384499\n" + "7494-04-103-REV-NONE\n" + "14A1669D2F1-REV-J\n" + "4212.8801-REV-O\n" + "2373 FINISH\n" + "2372 TAPER\n" + "SHARPE-36465 2ND\n" + "KOOTR KT300AL OP2\n" + "312-133034-001-REV-B\n" + "14A1937-REV-01\n" + "OSHKOSH/12611249/REV A/OP2\n" + "SANTASISE398FOP3\n" + "SIEMENS10248226REV08\n"; 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