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 single character of: a, b, c or d
    [[ab][cd]]
  • 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]
  • Character class intersection
    [\w&&[^\d]]
  • 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

"
"
gmi

Test String

Substitution

Processing...

Code Generator

Generated Code

re = /(?:^|\s)\S/mi str = 'usdfiusdgfisdgf LovePizza 12,34,56,78 12.34.56,78 Esto es una prueba hola 12345678 45345345343 Nananananananananananananananana Batman! nada@gmail.com lorena.loba@loquesea.gov.co hola_3@gmail.com adios@gmail.com pruebagmail.com pepe.trueno patricia99.rica@.hotmail.com lorena22.regalada comercio.enproceso daniela regalo gmail.com redluis.luis@gmail.com pepe_redluis@gmail.com pepe_redluis@gmail.com mart-red+luis@gmail.com.ve { "servicio":"eval", "eval":{ "10441":"valor.%substr%( 2, 2 )", "10442":"valor", "10443":"%mask%(valor,3)" }, "operacion":"valor.%concat%(10442,10443,10441)", "resultado":12022 } 1. Luciana: 4.216 2. Isabella: 3.505 3. Salomé: 2.829 4. Emmanuel: 2.688 5. Antonella: 2.643 6. Emiliano: 2454 7. Santiago: 2.383 8. Samuel: 2.256 9. Jerónimo: 2.167 10. Mariana: 2.160 date,home_team,away_team,home_score,away_score,tournament,city,country,neutral 1872-11-30,Scotland,England,0,0,Friendly,Glasgow,Scotland,FALSE 1873-03-08,England,Scotland,4,2,Friendly,London,England,FALSE 1874-03-07,Scotland,England,2,1,Friendly,Glasgow,Scotland,FALSE 1875-03-06,England,Scotland,2,2,Friendly,London,England,FALSE 1876-03-04,Scotland,England,3,0,Friendly,Glasgow,Scotland,FALSE 1876-03-25,Scotland,Wales,4,0,Friendly,Glasgow,Scotland,FALSE 1::Toy Story (1995)::Adventure|Animation|Children|Comedy|Fantasy 2::Jumanji (1995)::Adventure|Children|Fantasy 3::Grumpier Old Men (1995)::Comedy|Romance 4::Waiting to Exhale (1995)::Comedy|Drama|Romance 5::Father of the Bride Part II (1995)::Comedy 6::Heat (1995)::Action|Crime|Thriller 7::Sabrina (1995)::Comedy|Romance 8::Tom and Huck (1995)::Adventure|Children 9::Sudden Death (1995)::Action 10::GoldenEye (1995)::Action|Adventure|Thriller 11::American President, The (1995)::Comedy|Drama|Romance 12::Dracula: Dead and Loving It (1995)::Comedy|Horror 13::Balto (1995)::Animation|Children 14::Nixon (1995)::Drama 15::Cutthroat Island (1995)::Action|Adventure|Romance 16::Casino (1995)::Crime|Drama 17::Sense and Sensibility (1995)::Comedy|Drama|Romance 18::Four Rooms (1995)::Comedy|Drama|Thriller 19::Ace Ventura: When Nature Calls (1995)::Comedy 20::Money Train (1995)::Action|Comedy|Crime|Drama|Thriller' subst = '' result = str.gsub(re, subst) # Print the result of the substitution puts 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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html