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"
"
g

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"[A-Z][a-z]+[,;\s\&]*(?:[A-Z][a-z]|\s*et al\.\s*)*(?:, \d{4};?)+"; string input = @"(Kim et al., 2004) (Kim et al., 2004; Sun et al., 2014; Hinuma et al., 2012; Masubuchi, 2013) ( No. 221) with the O/N anions completely disordered in the anion octahedra (Kim et al., 2004; Pors et al., 1988; Fig. 1). The situation of SrTaO2N is more complex, and several structural models have been reported: I4/mcm (No. 140; Gu nther et al., 2000; Zhang et al., 2011; Kim et al., 2004; Clarke et al., 2002), I112/m (No. 12; Yang et al., 2011) and Fmmm (No. 69; Clark et al., 2013). (Higashi et al., 2008, 2013, 2015; Oehler & Ebbinghaus, 2016; Ueda et al., 2015) Oehler & Ebbinghaus, 2016; A further Ta- O/N octahedra displacement [R 5 - (a,0,0), rotation about the c axis] distortion was observed in SrTaO2N. This distortion mode is accompanied by an increased unit-cell distortion that decreases as the temperature increases. Ultimately a second-order phase transition caused by the loss of the R 5 - (a,0,0) mode was observed at 400- 450 K. Mixed anion materials, in particular oxynitrides, are attracting considerable attention for their novel properties. SrTaO2N and BaTaO2N are two typical perovskite oxynitrides that have been widely studied due to their promising properties that include semiconductivity (Kim et al., 2004), dielectric relaxation (Kim et al., 2004; Sun et al., 2014; Hinuma et al., 2012; Masubuchi, 2013) and photocatalytic activity (Higashi et al., 2008, 2013, 2015; Oehler & Ebbinghaus, 2016; Ueda et al., 2015). Evidently the distortion of the octahedra in perovskite oxynitrides is a key parameter in understanding their interesting properties. Thus, a careful and systematic study of the Ta- O/N octahedra distortion in SrTaO2N and BaTaO2N is likely to enhance our understanding of these fascinating materials."; foreach (Match m in Regex.Matches(input, pattern)) { Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index); } } }

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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx