Regular Expressions 101

Save & Share

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

/
/
xmsg

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/#проверка корректности даты в формате ГГГГ-ММ-ДД без проверки YYYY-02-29 в високосных годах (нужно доделать) (?=^ (?:19|20)\d\d #1900...2099 - (?: (?:0[1-9]|1[012]) #01...12 - (?:0?[1-9]|[12]\d) #01...29 | (?:0[13-9]|1[012]) #monthForDay30 - 30 | (?:0[13578]|1[02]) #monthForDay31 - 31 ) $) ^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/xms'; $str = '2018-01-00 2018-01-32 2018-00-01 2018-13-01 2018-01-01 2018-01-29 2018-01-30 2018-01-31 2018-02-29 2018-02-30 2018-02-31 2018-03-29 2018-03-30 2018-03-31 2018-04-29 2018-04-30 2018-04-31 2018-05-29 2018-05-30 2018-05-31 2018-06-29 2018-06-30 2018-06-31 2018-07-29 2018-07-30 2018-07-31 2018-08-29 2018-08-30 2018-08-31 2018-09-29 2018-09-30 2018-09-31 2018-10-29 2018-10-30 2018-10-31 2018-11-29 2018-11-30 2018-11-31 2018-12-29 2018-12-30 2018-12-31'; $subst = "${year}-${month}-${day}"; $result = preg_replace($re, $subst, $str); echo "The result of the substitution is ".$result;

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