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

/
/
gm

Test String

Code Generator

Generated Code

re = /(\d{10})_([A-Z][a-z]+)([A-Z][a-z]+)(\.[a-zA-Z]{3,4})/m str = '1173216167_AgentWill.jpg 1173216768_BrooksHarold.jpg 1173299189_BurgessDon.jpg 1173299407_ConiglioMike.jpg 1173299438_CooperKaren.jpg 1173299499_CurtisChristopher.jpg 1173300038_ElmoreKim.jpg 1173300155_FarmerVicki.jpg 1173300181_FletcherSteve.jpg 1173300207_ForrenEddie.jpg 1173300279_McguckinLinda.jpg 1173300440_GourleyJj.jpg 1173300567_HeinslemanPam.jpg 1173300593_HondlKurt.jpg 1173300619_HornJeff.jpg 1173300646_HowardKen.jpg 1173300716_IvicIgor.jpg 1173300757_JainMike.jpg 1173300862_KainJack.jpg 1173302066_KennedyDoug.jpg 1173302338_KuhlmanKristin.jpg 1173302528_LangstronCarrie.jpg 1173302580_LynnKelly.jpg 1173302631_MacgormanDon.jpg 1173303489_MelnikovValery.jpg 1173303530_MorrowBrett.jpg 1173303596_MurnanJames.jpg 1173303818_OrtegaKiel.jpg 1173304172_RabinBob.jpg 1173304254_RollinsTonia.jpg 1173304421_SchmidtMike.jpg 1173304508_SchurrTerry.jpg 1173304851_StumpfGreg.jpg 1173304935_TarpKeli.jpg 1173305069_ToomeyRobert.jpg 1173305102_TorresSebastian.jpg 1173305301_WickerLou.jpg 1173305326_WittArthur.jpg 1173305357_WoodBim.jpg 1173305420_XuQin.jpg 1173305550_YussoufNusrat.jpg 1173305582_ZahraiAllen.jpg 1173305608_ZhangPengfei.jpg 1173305634_ZhangJian.jpg 1173305666_ZieglerConrad.jpg 1173305696_ZrnicDusan.jpg 1178031443_LewisJohn.jpg 1208811784_DoviakRichard.jpg 1208811993_KrauseJohn.jpg 1208812047_MansellTed.jpg 1208812483_PepplerRandy.jpg 1208812511_ReevesHeather.jpg 1208812542_RobertsBrett.jpg 1208812597_WaughSean.jpg 1248986831_Warde-David.jpg 1248987295_Smith--Travis.jpg 1248987685_Knopfmeier--Kent.jpg 1248987721_GRIFFIN-ERICA.jpg 1248987828_Brogden--Jeff.jpg 1248987872_Arthur-Ami.jpg 1249399247_Nemunaitis-Kodi.jpg 1258400095_Clark-Adam.jpg 1258400182_Stratman-Derek.jpg 1258755192_Schwarz--Chris.jpg 1271793238_humberto.jpg 1273024015_BrianKaney2003.jpg 1278003921_Butler-Sterling.jpg 1278004017_Reinke-Tracy.jpg 1278004036_Ryzhkov-Alexander.jpg 1278004055_Tang-Lin.jpg 1278004074_Wang-Yadong.jpg 1297362249_Jones-Thomas.jpg 1297362283_Potvin-Corey.jpg 1311024411_Crank-Linda.jpg 1311024437_Gao-Jidong.jpg 1311024633_Smith-Brandon.jpg 1391808396_Bowden-Katie.jpg 1401375264_Meitin_jose.jpg 1407171270_Carlin_Jacob.jpg 1407171306_Cocks_Stephen.jpg 1407171371_Creager_Gerald.jpg 1407171682_Kirstetter-Pierre.jpg 1407171749_Kuster_Charles.jpg 1407171773_Martinaitis_Steven.jpg 1407171792_Mirkovic_Djordje.jpg 1407171905_Shattuck_Micheal.jpg 1407171947_Snyder_Jeffrey.jpg 1407172034_Wadler_Joshua.jpg 1418052845_D-Wasielewski.jpg' # 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