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 = ";;\\s*basic\\sblock\\s(\\d+),\\sloop\\sdepth\\s\\d\\s;;\\s*pred:\\s*\\w*\\s;;\\s*starting\\sat\\sline\\s(\\d+)"; final String string = "\n" + ";; Function main (main, funcdef_no=13, decl_uid=3054, cgraph_uid=13, symbol_order=13)\n\n" + "Removing basic block 7\n" + "Merging blocks 5 and 6\n" + ";; 1 loops found\n" + ";;\n" + ";; Loop 0\n" + ";; header 0, latch 1\n" + ";; depth 0, outer -1\n" + ";; nodes: 0 1 2 3 4 5 6\n" + ";; 2 succs { 3 4 }\n" + ";; 3 succs { 5 }\n" + ";; 4 succs { 5 }\n" + ";; 5 succs { 6 }\n" + ";; 6 succs { 1 }\n" + "main ()\n" + "{\n" + " int n;\n" + " int D.3061;\n\n" + ";; basic block 2, loop depth 0\n" + ";; pred: ENTRY\n" + ";; starting at line 7\n" + " [D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:7:4] __builtin_puts (&\"Enter an integer\"[0]);\n" + " [D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:8:4] scanf ([D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:8:10] \"%d\", [D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:8:4] &n);\n" + " [D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:10:12] n.0_1 = n;\n" + " [D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:10:12] n.1_2 = (unsigned int) n.0_1;\n" + " [D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:10:12] _3 = n.1_2 & 1;\n" + " [D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:10:7] if (_3 == 0)\n" + " goto <bb 3>; [0.00%]\n" + " else\n" + " goto <bb 4>; [0.00%]\n" + ";; succ: 3\n" + ";; 4\n\n" + ";; basic block 3, loop depth 0\n" + ";; pred: 2\n" + ";; starting at line 11\n" + " [D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:11:7] __builtin_puts (&\"Even\"[0]);\n" + " [0:0] goto <bb 5>; [0.00%]\n" + ";; succ: 5\n\n" + ";; basic block 4, loop depth 0\n" + ";; pred: 2\n" + ";; starting at line 13\n" + " [D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:13:7] __builtin_puts (&\"Odd\"[0]);\n" + ";; succ: 5\n\n" + ";; basic block 5, loop depth 0\n" + ";; pred: 3\n" + ";; 4\n" + ";; starting at line 15\n" + " [D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:15:11] D.3061 = 0;\n" + " n = {CLOBBER};\n" + ";; succ: 6\n\n" + ";; basic block 6, loop depth 0\n" + ";; pred: 5\n" + ";; starting at line -1, discriminator 1\n" + "<L4> [0.00%]:\n" + " return D.3061;\n" + ";; succ: EXIT\n\n" + "}\n\n\n\n" + ";; Function _GLOBAL__sub_I_00100_0_main (_GLOBAL__sub_I_00100_0_main, funcdef_no=14, decl_uid=3094, cgraph_uid=0, symbol_order=17)\n\n" + ";; 1 loops found\n" + ";;\n" + ";; Loop 0\n" + ";; header 0, latch 1\n" + ";; depth 0, outer -1\n" + ";; nodes: 0 1 2\n" + ";; 2 succs { 1 }\n" + "_GLOBAL__sub_I_00100_0_main ()\n" + "{\n" + ";; basic block 2, loop depth 0\n" + ";; pred: ENTRY\n" + ";; starting at line 16\n" + " [D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:16:1] __gcov_init ([D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:16:1] &*.LPBX0);\n" + " [D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:16:1] return;\n" + ";; succ: EXIT\n\n" + "}\n\n\n\n" + ";; Function _GLOBAL__sub_D_00100_1_main (_GLOBAL__sub_D_00100_1_main, funcdef_no=15, decl_uid=3097, cgraph_uid=1, symbol_order=18)\n\n" + ";; 1 loops found\n" + ";;\n" + ";; Loop 0\n" + ";; header 0, latch 1\n" + ";; depth 0, outer -1\n" + ";; nodes: 0 1 2\n" + ";; 2 succs { 1 }\n" + "_GLOBAL__sub_D_00100_1_main ()\n" + "{\n" + ";; basic block 2, loop depth 0\n" + ";; pred: ENTRY\n" + ";; starting at line 16\n" + " [D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:16:1] __gcov_exit ();\n" + " [D:\\Kuliah\\Semester8\\TA2\\TestObject\\EvenOdd\\evenodd.c:16:1] return;\n" + ";; succ: EXIT\n\n" + "}\n\n\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