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
No Match

r"
"
gm

Test String

Code Generator

Generated Code

re = /(?:(?<!\d|\-|\+|\.)(?P<ch_a>[\u4e00-\u9fff]{2})?(?P<Hours>[0-2]?\d)(?:[:\.时時]| ?h ?)(?P<Minutes>[0-5]\d(?!\d))\:?(?:(?:[:\.分]| ?m ?)(?P<Seconds>[0-5]\d(?!\d)))?秒?(?:[,\.](?P<SecodsFraction>\d{9}|\d{6}|\d{3}(?!\d)))?(?:\ \w\W)?(?:[\.\s]?(?:(?P<Z>(?:[a-zA-Z]{3,5}|Z|\[\w+\/\w+\])|(?:[+-]\d\d?\:?[0,3,4]?[0,5]?))|(?P<a>[dapmDAPM]{2})))*(?!\S))/m str = '19990322+0100 19990322 1999-03-22 AD 1999-03-22+01:00 1999-03-22T05:06:07.000[Europe/Paris] 1999-03-22T05:06:07.000 1999-03-22T05:06:07 1999-03-22T05:06:07.000Z 1999-03-22T05:06:07.000+01:00 1999-03-22T05:06:07+01:00 1999-081+01:00 1999W132 1999-W13-2 1999-03-22T05:06:07.000+01:00[Europe/Paris] 1999-03-22T05:06:07+01:00[Europe/Paris] 22.3.99 22.3.99 5.06 22.3.1999 5.06.07 22.3.1999 5:06:07 22-03-99 22-03-99 05:06 22-03-1999 05:06:07 22.03.99 22. März 1999 Montag, 22. März 1999 22.03.1999 22.03.99 05:06 22. März 1999 05:06:07 MEZ 22.03.1999 05:06:07 22.03.99 05:06:07 22.03.1999 05:06 Montag, 22. März 1999 05:06 Uhr MEZ 22-Mar-1999 22/03/99 5:06 AM Monday, March 22, 1999 5:06:07 o\'clock AM CET 22-Mar-1999 5:06:07 AM 22 March 1999 Monday, 22 March 1999 22-Mar-1999 22 March 1999 05:06:07 CET Monday, 22 March 1999 05:06:07 o\'clock CET 22-Mar-1999 05:06:07 22-Mar-99 05.06.07.000000888 AM 3/22/99 03/11/22 03-22-99 3-22-99 Mar 22, 1999 March 22, 1999 Monday, March 22, 1999 Mar 22 1999 March 22 1999 03-22-1999 3-22-1999 1999-03-22+01:00 22/03/1999 22/3/1999 03/22/1999 3/22/1999 1999/3/22 3/22/99 5:06 AM 03/22/99 5:06 AM 03-22-99 5:06 AM 3-22-99 5:06 AM Mar 22, 1999 5:06:07 AM Monday, March 22, 1999 5:06:07 AM CET Mon Mar 22 05:06:07 CET 1999 Mon, 22 Mar 1999 05:06:07 +0100 22 Mar 1999 05:06:07 +0100 03-22-1999 5:06:07 AM 3-22-1999 5:06:07 AM 1999-03-22 5:06:07 AM 1999-3-22 5:06:07 AM 1999-03-22 05:06:07.0 22/03/1999 5:06:07 AM 22/3/1999 5:06:07 AM 03/22/1999 5:06:07 AM 3/22/1999 5:06:07 AM 03/22/99 5:06:07 AM 03/22/99 5:06:07 3/22/99 5:06:07 22/03/1999 5:06 AM 22/3/1999 5:06 AM 03/22/1999 5:06 AM 3/22/1999 5:06 AM 03-22-99 5:06:07 AM 3-22-99 5:06:07 AM 03-22-1999 5:06 AM 3-22-1999 5:06 AM 1999-03-22 5:06 AM 1999-3-22 5:06 AM Mar.22.1999 22/Mar/1999 5:06:07 +0100 22/Mar/99 5:06 AM 22/03/99 22/03/99 5:06 22.3.99 5:06 22.03.99 22.03.1999 22.03.99 5:06 22.03.1999 5:06:07 22.3.1999 22.3.1999 5:06 99-03-22 1999-03-22 22 mars 1999 05:06:07 CET March 22, 1999 5:06:07 CET AM 1999-03-22 05:06:07 lundi 22 mars 1999 5 h 06 CET 22/03/99 22 mars 1999 22 mars 1999 lundi 22 mars 1999 22/03/99 05:06 03/22/99 05:06 3/22/99 05:06 03-22-99 05:06 3-22-99 05:06 22 mars 1999 05:06:07 22 mars 1999 05:06:07 CET 03-22-1999 05:06:07 3-22-1999 05:06:07 1999-3-22 05:06:07 22/03/1999 05:06:07 22/3/1999 05:06:07 03/22/1999 05:06:07 3/22/1999 05:06:07 lundi 22 mars 1999 05 h 06 CET 22/03/99 05:06:07 03/22/99 05:06:07 3/22/99 05:06:07 22/03/1999 05:06 22/3/1999 05:06 03/22/1999 05:06 3/22/1999 05:06 03-22-99 05:06:07 3-22-99 05:06:07 03-22-1999 05:06 3-22-1999 05:06 1999-3-22 05:06 99/03/22 05:06 1999.03.22 1999.03.22 05:06:07 1999.03.22 05:06 1999.03.22. 1999.03.22. 5:06:07 1999.03.22. 5:06 22.3.1999 05:06:07 22.3.1999 05:06 22-mar-1999 22/03/99 5.06 99-03-22 05:06 22-mar-1999 5.06.07 22 marzo 1999 5.06.07 CET lunedì 22 marzo 1999 5.06.07 CET 05:06 22/03/99 05:06:07 22/03/1999 99/03/22 1999/03/22 99/03/22 5:06 03/22/99 5:06 3/22/99 5:06 03-22-99 5:06 3-22-99 5:06 AM 03-22-1999 5:06:07 3-22-1999 5:06:07 1999-03-22 5:06:07 99/03/22 5:06:07 3/22/99 5:06:07 AM 1999/03/22 5:06 22/03/1999 5:06 22/3/1999 5:06 03/22/1999 5:06 3/22/1999 5:06 03-22-99 5:06:07 3-22-99 5:06:07 03-22-1999 5:06 3-22-1999 5:06 1999-03-22 5:06 1999-3-22 5:06 99. 3. 22 1999. 3. 22 99.3.22 99.3.22 05.06 1999-03-22 05.06.07 99.22.3 1999.22.3 99.22.3 05:06 1999.22.3 05:06:07 22.3.99 05:06 22.3.1999 05:06: 22-3-99 22-3-99 5:06 22-03-1999 22-03-1999 5:06 22.03.99 5:06 22.03.1999 5:06:07 1999-03-22 5:06:07.PD 99-03-22 5.06.PD 1999-03-22 5.06.07.PD CET 22.3.99. 22.03.1999. 22.3.99. 05.06 22.03.1999. 05.06.07 22.03.1999. 05.06.07 CET 05:06:07 22-03-1999 05:06 22/03/1999 99-3-22 1999-3-22 1999年3月22日 1999年3月22日 星期一 99-3-22 上午5:06 1999-3-22 5:06:07 1999年3月22日 上午05时06分07秒 1999年3月22日 5時06分07秒 CET 1999年3月22日 星期一 上午05时06分07秒 CET ' # 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