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

~
~
sg

Test String

Code Generator

Generated Code

$re = '~(.*?) => (\d+)(?: *\R|$)~s'; $str = '0 => 129367 1 => 998023 2 => 971513 3 => 365366 4 => 247647 5 => 131747 6 => 86151 7 => 898342 8 => 591121 9 => 828966 a => 185363 b => 420016 c => 472728 d => 185475 e => 669058 f => 472944 g => 932915 h => 109171 i => 940561 j => 483250 k => 240419 l => 158223 m => 494635 n => 205943 o => 19961 p => 989725 q => 125777 r => 195604 s => 818227 t => 83779 u => 990539 v => 639213 w => 669743 x => 546240 y => 950155 z => 631005 A => 126161 B => 403898 C => 323151 D => 536228 E => 653494 F => 810236 G => 808261 H => 900915 I => 60916 J => 417663 K => 371534 L => 384244 M => 900004 N => 300998 O => 346538 P => 5044 Q => 558707 R => 404479 S => 183163 T => 505254 U => 497969 V => 197795 W => 953877 X => 394637 Y => 760236 Z => 211436 ! => 601326 " => 15745 # => 428427 $ => 602548 % => 938126 & => 159405 \' => 528113 ( => 8021 ) => 910309 * => 747795 + => 232242 , => 731593 - => 808534 . => 429705 / => 916854 : => 241543 ; => 755104 < => 314595 = => 398161 > => 606925 ? => 804662 @ => 713498 [ => 431477 \\ => 80381 ] => 36645 ^ => 156790 _ => 34787 ` => 107682 { => 283663 | => 650856 } => 91921 ~ => 752056 => 494223 => 521932 => 816279 => 301703 => 17163 => 867641 ą => 817209 ś => 594615 ż => 570356 ź => 913303 ł => 752084 ó => 838178 ę => 693877 ń => 564418 ć => 30975 Ż => 707466'; 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