Regular Expressions 101

Save & Share

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

$re = '/\b(\w+)\(/m'; $str = '=SPARKLINE( ArrayFormula({ QUERY(ArrayFormula({ 0, 0, 1 + N("See Comment 1"); 0, 0, 0.8 + N("See Comment 2") ; SEQUENCE(37,1,0,10), SIN(RADIANS(SEQUENCE(37,1,0,10))), COS(RADIANS(SEQUENCE(37,1,0,10))) + N("See Comment 3") ; SEQUENCE(12,1,30,30), 0.9 * SIN(RADIANS(SEQUENCE(12,1,30,30))), 0.9 * COS(RADIANS(SEQUENCE(12,1,30,30))) + N("See Comment 4") ; SEQUENCE(12,1,30,30), SIN(RADIANS(SEQUENCE(12,1,30,30))), COS(RADIANS(SEQUENCE(12,1,30,30))) + N("See Comment 5") ; SEQUENCE(4,1,90,90), 0.8 * SIN(RADIANS(SEQUENCE(4,1,90,90))), 0.8 * COS(RADIANS(SEQUENCE(4,1,90,90))) + N("See Comment 6") ; SEQUENCE(4,1,90,90), SIN(RADIANS(SEQUENCE(4,1,90,90))), COS(RADIANS(SEQUENCE(4,1,90,90))) + N("See Comment 7") }), "SELECT Col2, Col3 ORDER BY Col1", 0 + N("See Comment 8") ) ; IF( MINUTE(NOW()) = 0, 0, SIN(RADIANS(SEQUENCE(MINUTE(NOW())/60*360,1,1,1))) ), IF( MINUTE(NOW())=0, 1, COS(RADIANS(SEQUENCE(MINUTE(NOW())/60*360,1,1,1))) ) + N("See Comment 9"); 0, 0 + N("See Comment 10") ; 0.75 * SIN(RADIANS((MOD(HOUR(NOW()),12)/12 * 360) + MINUTE(NOW())/60 * 30)), 0.75 * COS(RADIANS((MOD(HOUR(NOW()),12)/12 * 360) + MINUTE(NOW())/60 * 30)) + N("See Comment 11") }), {"linewidth",2 + N("See Comment 12") + N(" Comments: 1: Initial (0,1) coordinate at top of circle. Extra 0 included for sort. 2: Coordinates to create mark at 12 o\'clock. 3: Coordinates to draw initial circle. Joins markers every 10 degrees starting from 0 at top of circle, e.g. 0, 10, 20, 30,...360 4: Sequence of coordinates every 30 degrees to create small markers for hours 1, 2, 4, 5, 7, 8, 10, 11 5: Sequence of coordinates to connect the 30 degree small markers. Needed to place them correctly on circle. 6: Sequence of coordinates every 90 degrees to create large markers for hours 12, 3, 6, 9 7: Sequence of coordinates to connect the 90 degree large markers. Needed to place them correctly on circle. 8: QUERY function used to sort the circle data by the degrees column, then select just the (x,y) coordinate columns (numbers 2 and 3) to use. 9: Coordinates to create the minute hand. Includes an IF statement to avoid an error when the minute hand arrives at the 12 mark. 10: Coordinates to return to centre of clock at (0,0) after minute hand, to be ready to draw hour hand. 11: Coordinates to create the hour hand. 12: Set linewidth of the Sparkline to 2. . . Google Sheets Formula Clock June 2019 Created by Ben Collins, Google Developer Expert and Founder of The Collins School Of Data Website: benlcollins.com Twitter: @benlcollins ")} ) '; 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