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

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

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php