Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • 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
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
Processing...

Test String

Code Generator

Generated Code

re = /(((((0[1-9]|[1-2][0-9]|30)-(0[13-9]|1[0-2]))|((0[1-9]|1[0-9]|2[0-8])-02)|(31-(0[13578]|1[02])))-\d{4})|(29-02-((\d{2}(([2468]0)|([02468][48])|([13579][26])))|((([02468][048])|([13579][26]))0{2}))))/m str = '28-01-0001 28-02-0001 28-03-0001 28-04-0001 28-05-0001 28-06-0001 28-07-0001 28-08-0001 28-09-0001 28-10-0001 28-11-0001 28-12-0001 29-01-0001 29-02-0001 29-03-0001 29-04-0001 29-05-0001 29-06-0001 29-07-0001 29-08-0001 29-09-0001 29-10-0001 29-11-0001 29-12-0001 30-01-0001 30-02-0001 30-03-0001 30-04-0001 30-05-0001 30-06-0001 30-07-0001 30-08-0001 30-09-0001 30-10-0001 30-11-0001 30-12-0001 31-01-0001 31-02-0001 31-03-0001 31-04-0001 31-05-0001 31-06-0001 31-07-0001 31-08-0001 31-09-0001 31-10-0001 31-11-0001 31-12-0001 29-02-0001 29-02-0002 29-02-0003 29-02-0004 29-02-0005 29-02-0006 29-02-0007 29-02-0008 29-02-0009 29-02-0010 29-02-0020 29-02-0030 29-02-0040 29-02-0050 29-02-0060 29-02-0070 29-02-0080 29-02-0090 29-02-0100 29-02-0110 29-02-0120 29-02-0130 29-02-0140 29-02-0150 29-02-0160 29-02-0170 29-02-0180 29-02-0190 29-02-0200 29-02-0300 29-02-0400 29-02-0500 29-02-0600 29-02-0700 29-02-0800 29-02-0900 29-02-1000 29-02-1100 29-02-1200 29-02-1300 29-02-1400 29-02-1500 29-02-1600 29-02-1700 29-02-1800 29-02-1900 29-02-2000' # Print the match result str.scan(re) do |match| puts match.to_s end

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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html