Regular Expressions 101

Save & Share

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 = '/\[[0-9]+[;]?[1H\[K\[7mlines [0-9-]+ \[[0-9]+m\[60;1H\[60;1H/m'; $str = 'lines 17464-17522  140.90.101.62-NOAA { ip-netmask 140.90.101.62; tag GLOBAL-WEATHER; description "Weather - NOAA National Center for Environmental Prediction - Contact WCOC DSN 271-2586"; } 140.172.138.17-NOAA { ip-netmask 140.172.138.17; tag GLOBAL-WEATHER; description "Weather - NOAA Operational Model Archive and Distro System (NOMADS-HTTPS) National Center for Environmental Prediction (NCEP-FTP) - Contact WCOC DSN 271-2586"; } 128.132.41.26-AFRL { ip-netmask 128.132.41.26; tag GLOBAL-WEATHER; description "Weather - CAOC AF Research Lab - Contact WCOC DSN 271-2586"; } 140.172.138.18-NOAA { ip-netmask 140.172.138.18; tag GLOBAL-WEATHER; description "Weather - NOAA Operational Model Archive and Distro System - HTTPS - Contact WCOC DSN 271-2586"; } 204.0.3.146 { ip-netmask 204.0.3.146; tag GLOBAL-WEATHER; description "Weather - Intellicast - Contact WCOC DSN 271-2586"; } 192.145.239.17 { ip-netmask 192.145.239.17; tag GLOBAL-WEATHER; description "Weather - Hurrtrack - Contact WCOC DSN 271-2586"; } 70.39.145.13 { ip-netmask 70.39.145.13; tag GLOBAL-WEATHER; description "Weather - Hurrtrack - Contact WCOC DSN 271-2586"; } 204.0.3.147 { ip-netmask 204.0.3.147; tag GLOBAL-WEATHER; description "Weather - Intellicast - Contact WCOC DSN 271-2586"; } 140.172.17.191-NOAA { ip-netmask 140.172.17.191; tag GLOBAL-WEATHER; description "Weather - NOAA Aviation Weather Center - Contact WCOC DSN 271-2586"; } 140.90.200.191-NOAA { ip-netmask 140.90.200.191; tag GLOBAL-WEATHER; description "Weather - NOAA Aviation Weather Center - Contact WCOC DSN 271-2586"; } 129.15.96.191-NOAA { ip-netmask 129.15.96.191; tag GLOBAL-WEATHER; description "Weather - NOAA Aviation Weather Center - Contact WCOC DSN 271-2586"; } 23.3.96.193-NOAA { ip-netmask 23.3.96.193; tag GLOBAL-WEATHER; description "Weather - NOAA - NWS Radar Sites - Contact WCOC DSN 271-2586"; lines 17523-17581  } 205.156.4.51-NOAA { ip-netmask 205.156.4.51; tag GLOBAL-WEATHER; description "Weather - NOAA - Web Map Service - Contact WCOC DSN 271-2586"; } 23.3.96.242-NOAA { ip-netmask 23.3.96.242; tag GLOBAL-WEATHER; description "Weather - NOAA - NWS Radar Sites - Contact WCOC DSN 271-2586"; } 199.212.17.28 { ip-netmask 199.212.17.28; tag GLOBAL-WEATHER; description "Weather - Canadian Weather - Contact WCOC DSN 271-2586"; } 199.212.17.39 { ip-netmask 199.212.17.39; tag GLOBAL-WEATHER; description "Weather - Canadian Weather - Contact WCOC DSN 271-2586"; } 192.139.6.68 { ip-netmask 192.139.6.68; tag GLOBAL-WEATHER; description "Weather - Canadian Northern Forestry Center - Contact WCOC DSN 271-2586"; } 140.90.101.79-NOAA { ip-netmask 140.90.101.79; tag GLOBAL-WEATHER; description "Weather - NOAA NWS/NCEP TGFTP server - Contact WCOC DSN 271-2586"; } 140.90.101.34-NOAA { ip-netmask 140.90.101.34; tag GLOBAL-WEATHER; description "Weather - NOAA NWS/NCEP FTP HPC Anony server - Contact WCOC DSN 271-2586"; } 140.90.101.132-NOAA { ip-netmask 140.90.101.132; tag GLOBAL-WEATHER; description "Weather - NOAA NWS/NCEP Wind/Wave server - Contact WCOC DSN 271-2586"; } 140.172.138.79-NOAA { ip-netmask 140.172.138.79; tag GLOBAL-WEATHER; description "Weather - NOAA NWS/NCEP TGFTP server - Contact WCOC DSN 271-2586"; } 140.90.213.161-NOAA { ip-netmask 140.90.213.161; tag GLOBAL-WEATHER; description "Weather - NOAA NESDIS server - Contact WCOC DSN 271-2586"; } 140.90.195.198-NOAA { ip-netmask 140.90.195.198; tag GLOBAL-WEATHER; description "Weather - NOAA National Center for Environmental Prediction - Contact WCOC DSN 271-2586"; } 140.90.192.168-NOAA { ip-netmask 140.90.192.168; tag GLOBAL-WEATHER; lines 17582-17640  description "Weather - NOAA National Center for Environmental Prediction - Contact WCOC DSN 271-2586"; } 128.118.28.249-PSU { ip-netmask 128.118.28.249; tag GLOBAL-WEATHER; description "Weather - Penn State Uni Bufkit - apps2.meteo.psu.edu - Contact WCOC DSN 271-2586"; } 140.90.128.71-NOAA { ip-netmask 140.90.128.71; tag GLOBAL-WEATHER; description "Weather - NOAA National Center for Environmental Prediction - Contact WCOC DSN 271-2586"; } 140.90.88.142-NOAA { ip-netmask 140.90.88.142; tag GLOBAL-WEATHER; description "Weather - NOAA National Center for Environmental Prediction - Contact WCOC DSN 271-2586"; } 140.90.33.41-NOAA { ip-netmask 140.90.33.41; tag GLOBAL-WEATHER; description "Weather - NOAA National Center for Environmental Prediction - Contact WCOC DSN 271-2586"; } 140.90.33.31-NOAA { ip-netmask 140.90.33.31; tag GLOBAL-WEATHER; description "Weather - NOAA National Center for Environmental Prediction - Contact WCOC DSN 271-2586"; } 144.183.222.21 { ip-netmask 144.183.222.21; } 144.183.32.21 { ip-netmask 144.183.32.21; } 199.124.100.0_22 { ip-netmask 199.124.100.0/22; } 199.124.104.0_23 { ip-netmask 199.124.104.0/23; } 199.124.96.15-199.124.96.18 { ip-range 199.124.96.15-199.124.96.18; } 199.225.7.15 { ip-netmask 199.225.7.15; } 214.2.155.12-214.2.155.231 { ip-range 214.2.155.12-214.2.155.231; } 214.2.2.245 { ip-netmask 214.2.2.245; } 214.2.2.246 { ip-netmask 214.2.2.246; } 214.2.90.222 { ip-netmask 214.2.90.222; } 134.11.168.17 { ip-netmask 134.11.168.17; lines 17641-17699  description "Pentagon Army ROVR destination"; }'; 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