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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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"
"
mg

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"\(+(\H\o|[P]|\P\o|[G])\w+\s(\(\w+\s|\(\w+\s\()(\(\w+\s\w+\s\)\d+\s\)\d+\s\)\d+\s\)\d+\s\)|\w+\s\)\d+\s\)\d+\s\w+\s+\)\d+\s\)\d+\s)"; string input = @"(Macaca_mulatta Colobus_angolensis_palliatus (Pan_troglodytes_troglodytes ((Hylobates_agilis (Nomascus_leucogenys Symphalangus_syndactylus )21 )87 (Pongo_abelii (Homo_sapiens Gorilla_gorilla )64 )20 )12 )94 ) \)\d+\s\)\d+\s (\(\w+\s|\w+\s)(\)\d+|\w+)\s(\w+\s\)\d+|\)\d+\s\)\d+) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )55 )100 (Pongo_abelii (Homo_sapiens (Pan_troglodytes_troglodytes Gorilla_gorilla )63 )100 )83 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )86 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )99 )100 )73 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )91 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )81 )100 )87 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )72 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )94 )100 )93 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )58 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )90 )100 )83 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )68 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )81 )100 )72 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )90 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )92 )100 )99 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )68 )100 (Pongo_abelii (Homo_sapiens (Pan_troglodytes_troglodytes Gorilla_gorilla )89 )100 )99 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )47 )100 (Pongo_abelii (Pan_troglodytes_troglodytes (Gorilla_gorilla Homo_sapiens )48 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )81 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )71 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )29 )67 )84 (Hylobates_agilis (Symphalangus_syndactylus Nomascus_leucogenys )36 )99 )98 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )58 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )82 )100 )93 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )68 )100 (Pongo_abelii (Homo_sapiens (Gorilla_gorilla Pan_troglodytes_troglodytes )49 )100 )91 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )58 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )45 )100 )99 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Hylobates_agilis (Symphalangus_syndactylus Nomascus_leucogenys )35 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )43 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )45 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )90 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )44 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )63 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )97 )100 )97 ((Nomascus_leucogenys Symphalangus_syndactylus )40 Hylobates_agilis )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )43 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )46 )100 )96 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )46 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )100 )100 )99 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )52 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )94 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )57 )98 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )53 )100 )84 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )55 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )98 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )75 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )85 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )84 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )98 )100 )93 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )58 )100 )99 (Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )53 )100 )100 ) \(\((\H\y|[NS])\w+\s(\(\w+\s|\w+\s)(\)\d+|\w+)\s(\w+\s\)\d+|\)\d+\s\)\d+) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )57 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )93 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Hylobates_agilis (Symphalangus_syndactylus Nomascus_leucogenys )39 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )95 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )83 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )73 )100 )99 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )85 )100 )99 ((Hylobates_agilis Symphalangus_syndactylus )68 Nomascus_leucogenys )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )54 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )79 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )37 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )55 )100 )99 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Pongo_abelii (Gorilla_gorilla (Homo_sapiens Pan_troglodytes_troglodytes )86 )100 )78 (Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )64 )98 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )55 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )92 )100 )98 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )99 )100 )95 ((Hylobates_agilis Symphalangus_syndactylus )62 Nomascus_leucogenys )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )76 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )92 )100 )99 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )43 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )63 )100 )99 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )75 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )94 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Nomascus_leucogenys Hylobates_agilis )31 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )84 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )60 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )92 )100 )95 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )88 )100 )100 ((Hylobates_agilis Symphalangus_syndactylus )52 Nomascus_leucogenys )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )99 )100 )99 ((Hylobates_agilis Symphalangus_syndactylus )43 Nomascus_leucogenys )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )62 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )91 )100 )98 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )54 )98 (Pongo_abelii (Homo_sapiens (Gorilla_gorilla Pan_troglodytes_troglodytes )48 )100 )84 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )64 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )100 )100 )99 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )65 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )76 )100 )99 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )65 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )84 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )98 )100 )94 ((Hylobates_agilis Symphalangus_syndactylus )40 Nomascus_leucogenys )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )53 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )98 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )58 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )89 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )77 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )91 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )52 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )89 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )71 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )96 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )59 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )92 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )67 )100 (Pongo_abelii (Homo_sapiens (Pan_troglodytes_troglodytes Gorilla_gorilla )83 )100 )82 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )70 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )99 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )54 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )100 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )63 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )92 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )57 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )99 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )62 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )99 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )56 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )100 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )63 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )99 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )57 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )93 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )95 )100 )100 ((Hylobates_agilis Symphalangus_syndactylus )39 Nomascus_leucogenys )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )68 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )97 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )49 )100 ((Pan_troglodytes_troglodytes (Homo_sapiens Gorilla_gorilla )48 )100 Pongo_abelii )61 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Symphalangus_syndactylus Hylobates_agilis )63 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )96 )100 )100 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Symphalangus_syndactylus (Hylobates_agilis Nomascus_leucogenys )97 )100 (Pongo_abelii (Gorilla_gorilla (Homo_sapiens Pan_troglodytes_troglodytes )73 )100 )97 )100 ) (Macaca_mulatta Colobus_angolensis_palliatus ((Nomascus_leucogenys (Hylobates_agilis Symphalangus_syndactylus )81 )100 (Pongo_abelii (Gorilla_gorilla (Pan_troglodytes_troglodytes Homo_sapiens )54 )100 )72 )100 ) "; RegexOptions options = RegexOptions.Multiline; foreach (Match m in Regex.Matches(input, pattern, options)) { 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