Regular Expressions 101

Save & Manage Regex

  • Current Version: 3
  • 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 = '/^.{24}Realtime\[\d{1,3}\].*\n?/m'; $str = '2021-09-05 05:50:03.328 Realtime[248]: Uploading - realtimegauges.txt 2021-09-05 05:50:03.655 Realtime[248]: End cycle 2021-09-05 05:50:08.030 Realtime[249]: Start cycle 2021-09-05 05:50:08.030 Realtime[249]: Creating realtime.txt 2021-09-05 05:50:08.031 Realtime[249]: Processing realtime file - realtimegauges.txt 2021-09-05 05:50:08.046 Realtime[249]: Uploading - realtime.txt 2021-09-05 05:50:08.350 Realtime[249]: Uploading - realtimegauges.txt 2021-09-05 05:50:08.578 Realtime[249]: End cycle 2021-09-05 05:50:12.737 Reading live data 2021-09-05 05:50:12.759 DoCommand(CMD_GW1000_LIVEDATA): Valid response 2021-09-05 05:50:12.759 WH45 CO₂: Decoding... 2021-09-05 05:50:12.759 WH45 CO₂: temp=18.9, hum=62, pm10=1.6, pm10_24h=4.0, pm2.5=1.5, pm2.5_24h=3.2, CO₂=850, CO₂_24h=646 2021-09-05 05:50:13.030 Realtime[250]: Start cycle 2021-09-05 05:50:13.030 Realtime[250]: Creating realtime.txt 2021-09-05 05:50:13.031 Realtime[250]: Processing realtime file - realtimegauges.txt 2021-09-05 05:50:13.035 Realtime[250]: Uploading - realtime.txt 2021-09-05 05:50:13.263 Realtime[250]: Uploading - realtimegauges.txt 2021-09-05 05:50:13.503 Realtime[250]: End cycle 2021-09-05 05:50:15.232 Done creating graph data files 2021-09-05 05:50:16.020 Done uploading standard Data file 2021-09-05 05:50:17.666 GetAlCurrent: Outdoor - Waiting for lock 2021-09-05 05:50:17.666 GetAlCurrent: Outdoor - Has the lock 2021-09-05 05:50:17.666 GetAlCurrent: Outdoor - Sending GET current conditions request 1 to AL: http://192.168.59.236/v1/current_conditions ... 2021-09-05 05:50:17.774 DecodeAlCurrent: Outdoor - Found AirLink data 2021-09-05 05:50:17.774 DecodeAlCurrent: Outdoor - Using temp/hum data 2021-09-05 05:50:17.774 GetAlCurrent: Outdoor - Releasing lock 2021-09-05 05:50:18.030 Realtime[251]: Start cycle 2021-09-05 05:50:18.030 Realtime[251]: Creating realtime.txt 2021-09-05 05:50:18.032 Realtime[251]: Processing realtime file - realtimegauges.txt 2021-09-05 05:50:18.036 Realtime[251]: Uploading - realtime.txt 2021-09-05 05:50:18.303 Realtime[251]: Uploading - realtimegauges.txt 2021-09-05 05:50:18.577 Realtime[251]: End cycle 2021-09-05 05:50:20.937 Done uploading graph data files 2021-09-05 05:50:20.937 FTP[Int]: Uploading daily graph data files 2021-09-05 05:50:20.937 FTP[Int]: Done uploading daily graph data files '; 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