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

/
/
i

Test String

Substitution

Processing...

Code Generator

Generated Code

re = /\s+TStatusBar/i str = 'inherited FormPadrao: TFormPadrao Left = 354 Top = 155 Caption = \'FormPadrao\' ClientHeight = 342 ClientWidth = 655 KeyPreview = True PopupMenu = MnPop_Principal OnCloseQuery = FormCloseQuery OnDeactivate = FormDeactivate ExplicitWidth = 671 ExplicitHeight = 381 DesignSize = ( 655 342) PixelsPerInch = 96 TextHeight = 15 object Bv_Top: TBevel [0] Left = 0 Top = 0 Width = 655 Height = 2 Align = alTop end object Sb_FormPadrao: TStatusBar [1] Left = 0 Top = 317 Width = 655 Height = 25 Panels = < item Bevel = pbNone Text = \'Usu\'#225\'rio\' Width = 100 end item Bevel = pbNone Width = 50 end> ParentColor = True ParentFont = True UseSystemFont = False ExplicitTop = 323 end object Pn_BaseToolBar: TPanel [2] Left = 0 Top = 2 Width = 655 Height = 73 Align = alTop BevelOuter = bvNone ParentColor = True TabOrder = 2 end object Pn_BaseGrid: TPanel [3] Left = 0 Top = 75 Width = 655 Height = 242 Align = alClient BevelOuter = bvNone BorderWidth = 3 ParentColor = True TabOrder = 4 ExplicitLeft = 32 ExplicitTop = 95 ExplicitHeight = 222 end inherited MinMax: TmgMinMax Top = 7 MinTrackSize.X = 450 MinTrackSize.Y = 300 ExplicitTop = 7 end object Mn_Principal: TMainMenu [6] Left = 4 Top = 36 object miTabela: TMenuItem Caption = \'&Tabela\' object miInserir: TMenuItem Caption = \'&Inserir\' end object miApagar: TMenuItem Caption = \'&Apagar\' end object miPropriedades: TMenuItem Caption = \'&Editar\' end object N4: TMenuItem Caption = \'-\' end object miFechar: TMenuItem Caption = \'&Fechar\' OnClick = miFecharClick end end object miEditar1: TMenuItem Caption = \'&Editar\' object miRecortar1: TMenuItem Caption = \'&Recortar\' end object miCopiar1: TMenuItem Caption = \'&Copiar\' end object miColar1: TMenuItem Caption = \'&Colar\' end end object miExibir: TMenuItem Caption = \'&Exibir\' object miBarradeFerramentas: TMenuItem Caption = \'Barra de &Ferramentas\' object miNaoExibir: TMenuItem Caption = \'&N\'#227\'o Exibir\' GroupIndex = 1 RadioItem = True OnClick = mi_NaoExibirClick end object N5: TMenuItem Caption = \'-\' GroupIndex = 1 RadioItem = True end object miAlto: TMenuItem Caption = \'&Alto\' GroupIndex = 1 RadioItem = True OnClick = mi_AltoClick end object miBaixo: TMenuItem Caption = \'&Baixo\' GroupIndex = 1 RadioItem = True OnClick = mi_BaixoClick end end object miBarradeStatus: TMenuItem Caption = \'Barra de &Status\' OnClick = mi_BarradeStatusClick end object mi_SepN3: TMenuItem Caption = \'-\' end object mi_Informacoesdajanela1: TMenuItem Caption = \'Informa\'#231#245\'es desta Janela\' OnClick = mi_Informacoesdajanela1Click end object mi_Sepm9: TMenuItem Caption = \'-\' Visible = False end object mi_OcorrenciaAuditoria: TMenuItem Caption = \'Logs de Auditoria\' Visible = False OnClick = mi_OcorrenciaAuditoriaClick end end object Mi_Ajuda: TMenuItem Caption = \'&Ajuda\' object Mi_AjudaProcesso: TMenuItem Caption = \'Ajuda &Processo\' ShortCut = 112 OnClick = Mi_AjudaProcessoClick end object Mi_AjudaTela: TMenuItem Caption = \'Ajuda &Tela\' ShortCut = 16496 OnClick = Mi_AjudaTelaClick end object Mi_HistoricoAlteracoes: TMenuItem Caption = \'&Hist\'#243\'rico de altera\'#231#245\'es\' Visible = False OnClick = Mi_HistoricoAlteracoesClick end end end inherited mgPopupImpressao: TmgPopupMenu Left = 4 end object MnPop_Principal: TPopupMenu Left = 34 Top = 36 object mi_Inserir: TMenuItem Caption = \'&Inserir\' end object mi_Apagar: TMenuItem Caption = \'&Apagar\' end object mi_Editar: TMenuItem Caption = \'&Editar\' end object N1: TMenuItem Caption = \'-\' end object mi_BarradeFerramentas: TMenuItem Caption = \'&Barra de Ferramentas\' object mi_NaoExibir: TMenuItem Caption = \'&N\'#227\'o Exibir\' GroupIndex = 1 RadioItem = True OnClick = mi_NaoExibirClick end object N2: TMenuItem Caption = \'-\' GroupIndex = 1 RadioItem = True end object mi_Alto: TMenuItem Caption = \'&Alto\' GroupIndex = 1 RadioItem = True OnClick = mi_AltoClick end object mi_Baixo: TMenuItem Caption = \'&Baixo\' GroupIndex = 1 RadioItem = True OnClick = mi_BaixoClick end end object mi_BarradeStatus: TMenuItem Caption = \'Ba&rra de Status\' OnClick = mi_BarradeStatusClick end end end' subst = ' TMgStatusBar' result = str.sub(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